From: Christian Herdtweck Date: Mon, 20 Jun 2016 07:43:54 +0000 (+0200) Subject: use the "& 0xFFFfff" after all crc32 calculations X-Git-Tag: v2.2~22 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=c2ffe2ecabfde70102ea7225f96b1d7bfa290e83;p=python-delta-tar use the "& 0xFFFfff" after all crc32 calculations --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index bad7ec9..865841e 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -605,7 +605,7 @@ class DeltaTar(object): s = bytes('{"type": "BEGIN-FILE-LIST"}\n', 'UTF-8') # calculate checksum and write into the stream - crc = binascii.crc32(s) + crc = binascii.crc32(s) & 0xFFFFffff index_fd.write(s) # start creating the tarfile @@ -762,7 +762,7 @@ class DeltaTar(object): s = bytes('{"type": "BEGIN-FILE-LIST"}\n', 'UTF-8') # calculate checksum and write into the stream - crc = binascii.crc32(s) + crc = binascii.crc32(s) & 0xFFFFffff index_fd.write(s) # start creating the tarfile diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index ca5d557..f63b6ad 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -407,7 +407,7 @@ class _Stream: self.exception = zlib.error else: self._init_write_gz() - self.crc = zlib.crc32(b"") + self.crc = zlib.crc32(b"") & 0xFFFFffff elif comptype == "bz2": try: @@ -500,7 +500,7 @@ class _Stream: self.close(close_fileobj=False) self.closed = False self.concat_pos = 0 - self.crc = self.zlib.crc32(b"") + self.crc = self.zlib.crc32(b"") & 0xFFFFffff self.cmp = self.zlib.compressobj(self.compresslevel, self.zlib.DEFLATED, -self.zlib.MAX_WBITS, @@ -536,7 +536,7 @@ class _Stream: """Write string s to the stream. """ if self.comptype == "gz": - self.crc = self.zlib.crc32(s, self.crc) + self.crc = self.zlib.crc32(s, self.crc) & 0xFFFFffff self.pos += len(s) self.concat_pos += len(s) if self.comptype != "tar": @@ -756,7 +756,7 @@ class _Stream: raise ReadError("invalid compressed data") if self.comptype == "gz" and hasattr(self, "crc"): - self.crc = self.zlib.crc32(buf, self.crc) + self.crc = self.zlib.crc32(buf, self.crc) & 0xFFFFffff if self.concat_stream and len(self.cmp.unused_data) != 0: self.buf = self.cmp.unused_data + self.buf self.close(close_fileobj=False) @@ -765,7 +765,7 @@ class _Stream: except: # happens at the end of the file pass - self.crc = self.zlib.crc32(b"") + self.crc = self.zlib.crc32(b"") & 0xFFFFffff self.closed = False t.append(buf) c += len(buf) diff --git a/testing/test_deltatar.py b/testing/test_deltatar.py index e7cbe97..006ba7c 100644 --- a/testing/test_deltatar.py +++ b/testing/test_deltatar.py @@ -129,7 +129,7 @@ class DeltaTarTest(BaseTest): if l == b'': break if b'BEGIN-FILE-LIST' in l: - crc = binascii.crc32(l) + crc = binascii.crc32(l) & 0xFFFFffff began_list = True elif b'END-FILE-LIST' in l: crc = binascii.crc32(l, crc) & 0xffffffff