Skip to content

Commit

Permalink
fix(cpio): fixed checksum calculation to handle 4 byte overflows
Browse files Browse the repository at this point in the history
Checksum stored in the header is always 4 bytes in length, so when we calculate
the checksum, we need to sure that we only consider the 4bytes part and ommit
the overflown part.
  • Loading branch information
martonilles committed Nov 10, 2023
1 parent c040df9 commit f1f18d9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions unblob/handlers/archive/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ def valid_checksum(self, header, start_offset: int) -> bool:

for chunk in iterate_file(self.file, start_offset, file_size):
calculated_checksum += sum(bytearray(chunk))

return header_checksum == calculated_checksum
return header_checksum == calculated_checksum & 0xFF_FF_FF_FF


class _CPIOExtractorBase(Extractor):
Expand Down

0 comments on commit f1f18d9

Please sign in to comment.