]> granicus.if.org Git - python/commitdiff
A stab in the dark attempt to fix the alpha/tru64 buildbot problem and add more
authorGregory P. Smith <greg@mad-scientist.com>
Tue, 25 Mar 2008 06:12:45 +0000 (06:12 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Tue, 25 Mar 2008 06:12:45 +0000 (06:12 +0000)
test coverage of valid inputs to zlib.crc32.

Lib/tarfile.py
Lib/test/test_zlib.py

index 92fdb7b9d950e94d5893f930890c390f01ad12d8..4991ae1b60daf9498ad0625bd10d5f30e9ab27bf 100644 (file)
@@ -420,7 +420,7 @@ class _Stream:
             except ImportError:
                 raise CompressionError("zlib module is not available")
             self.zlib = zlib
-            self.crc = zlib.crc32("")
+            self.crc = zlib.crc32("") & 0xffffffffL
             if mode == "r":
                 self._init_read_gz()
             else:
@@ -458,7 +458,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) & 0xffffffffL
         self.pos += len(s)
         if self.comptype != "tar":
             s = self.cmp.compress(s)
index 9f0fe18c074b446a0a564e5d48e1662543f9be99..0c96842c77a7304f4e45f9fe36570f1bf100e1a2 100644 (file)
@@ -53,6 +53,15 @@ class ChecksumTestCase(unittest.TestCase):
         self.assertEqual(binascii.crc32(foo), zlib.crc32(foo))
         self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam'))
 
+    def test_negative_crc_iv_input(self):
+        # The range of valid input values for the crc state should be
+        # -2**31 through 2**32-1 to allow inputs artifically constrained
+        # to a signed 32-bit integer.
+        self.assertEqual(zlib.crc32('ham', -1), zlib.crc32('ham', 0xffffffffL))
+        self.assertEqual(zlib.crc32('spam', -3141593),
+                         zlib.crc32('spam',  0xffd01027L))
+        self.assertEqual(zlib.crc32('spam', -(2**31)),
+                         zlib.crc32('spam',  (2**31)))
 
 
 class ExceptionTestCase(unittest.TestCase):