Skip to content

Commit c8eb4aa

Browse files
committed
fix: Block checksum 32-bit overflow in _calc_chksum
The checksum accumulator was not masked to 32 bits during addition, only at the end. With Python's arbitrary-precision integers, this caused the sum to exceed 32 bits, producing wrong checksums for blocks with large unsigned values (common in RDB headers). Fix: mask with & 0xFFFFFFFF on each addition step. This fixes RDB validation failing on valid Amiga disk images.
1 parent 3b57f20 commit c8eb4aa

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

amitools/fs/block/Block.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _calc_chksum(self):
167167
chksum = 0
168168
for i in range(self.block_longs):
169169
if i != self.chk_loc:
170-
chksum += self._get_long(i)
170+
chksum = (chksum + self._get_long(i)) & 0xFFFFFFFF
171171
return (-chksum) & 0xFFFFFFFF
172172

173173
def _get_timestamp(self, loc):

0 commit comments

Comments
 (0)