use the "& 0xFFFfff" after all crc32 calculations
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 20 Jun 2016 07:43:54 +0000 (09:43 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Mon, 20 Jun 2016 07:44:30 +0000 (09:44 +0200)
deltatar/deltatar.py
deltatar/tarfile.py
testing/test_deltatar.py

index bad7ec9..865841e 100644 (file)
@@ -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
index ca5d557..f63b6ad 100644 (file)
@@ -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)
index e7cbe97..006ba7c 100644 (file)
@@ -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