[pypy-svn] r56599 - in pypy/dist/pypy/rlib: . test

exarkun at codespeak.net exarkun at codespeak.net
Wed Jul 16 20:09:27 CEST 2008


Author: exarkun
Date: Wed Jul 16 20:09:25 2008
New Revision: 56599

Modified:
   pypy/dist/pypy/rlib/rzipfile.py
   pypy/dist/pypy/rlib/test/test_rzipfile.py
Log:
Apply a 32bit mask to the CRC32 value to make the check correct on 64bit platforms

Modified: pypy/dist/pypy/rlib/rzipfile.py
==============================================================================
--- pypy/dist/pypy/rlib/rzipfile.py	(original)
+++ pypy/dist/pypy/rlib/rzipfile.py	Wed Jul 16 20:09:25 2008
@@ -181,7 +181,8 @@
             # file_offset must be computed below...
             (x.create_version, x.create_system, x.extract_version, x.reserved,
                 x.flag_bits, x.compress_type, t, d,
-                x.CRC, x.compress_size, x.file_size) = centdir[1:12]
+                crc, x.compress_size, x.file_size) = centdir[1:12]
+            x.CRC = r_uint(crc) & 0xffffffff
             x.dostime = t
             x.dosdate = d
             x.volume, x.internal_attr, x.external_attr = centdir[15:18]
@@ -237,7 +238,7 @@
                   "Unsupported compression method %d for file %s" % \
             (zinfo.compress_type, filename)
         crc = crc32(bytes)
-        if crc != r_uint(zinfo.CRC):
+        if crc != zinfo.CRC:
             raise BadZipfile, "Bad CRC-32 for file %s" % filename
         return bytes
     

Modified: pypy/dist/pypy/rlib/test/test_rzipfile.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rzipfile.py	(original)
+++ pypy/dist/pypy/rlib/test/test_rzipfile.py	Wed Jul 16 20:09:25 2008
@@ -16,6 +16,10 @@
         cls.year = time.localtime(time.time())[0]
         zipfile.writestr("one", "stuff")
         zipfile.writestr("dir" + os.path.sep + "two", "otherstuff")
+        # Value selected to produce a CRC32 which is negative if
+        # interpreted as a signed 32 bit integer.  This exercises the
+        # masking behavior necessary on 64 bit platforms.
+        zipfile.writestr("three", "hello, world") 
         zipfile.close()
     
     def test_rzipfile(self):
@@ -26,7 +30,8 @@
             rzip = RZipFile(zipname, "r", compression)
             info = rzip.getinfo('one')
             return (info.date_time[0] == year and
-                    rzip.read('one') == 'stuff')
+                    rzip.read('one') == 'stuff' and
+                    rzip.read('three') == 'hello, world')
 
         assert one()
         assert self.interpret(one, [])



More information about the Pypy-commit mailing list