Index: Lib/zipfile.py =================================================================== --- Lib/zipfile.py (revision 84573) +++ Lib/zipfile.py (working copy) @@ -1056,13 +1056,13 @@ # Must overwrite CRC and sizes with correct data later zinfo.CRC = CRC = 0 zinfo.compress_size = compress_size = 0 - zinfo.file_size = file_size = 0 self.fp.write(zinfo.FileHeader()) if zinfo.compress_type == ZIP_DEFLATED: cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15) else: cmpr = None + file_size = 0 while 1: buf = fp.read(1024 * 8) if not buf: @@ -1082,11 +1082,11 @@ zinfo.compress_size = file_size zinfo.CRC = CRC zinfo.file_size = file_size - # Seek backwards and write CRC and file sizes + # Seek backwards and write file header (which will now include + # correct CRC and file sizes) position = self.fp.tell() # Preserve current position in file - self.fp.seek(zinfo.header_offset + 14, 0) - self.fp.write(struct.pack("4GB + self.num_copies = 1 + (4*1024**3) // len(self.data) + f = open(TESTFN, "wb") + for i in range(self.num_copies): + f.write(self.data) + f.close() + + def zipTest(self, f, compression): + # Create the ZIP archive. + zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True) + zipfp.write(TESTFN, arcname="testfile") + zipfp.close() + + # Read the ZIP archive and verify its contents + zipfp = zipfile.ZipFile(f, "r") + f = zipfp.open("testfile") + for i in range(self.num_copies): + d = f.read(len(self.data)) + self.assertEqual(d, self.data) + # check that further reads retrieve no data + self.assertEqual(f.read(1), b"") + zipfp.close() + + def testStored(self): + self.zipTest(TESTFN2, zipfile.ZIP_STORED) + + if zlib: + def testDeflated(self): + self.zipTest(TESTFN2, zipfile.ZIP_DEFLATED) + + def tearDown(self): for fname in TESTFN, TESTFN2: if os.path.exists(fname): os.remove(fname) + - class OtherTests(unittest.TestCase): def testMoreThan64kFiles(self): # This test checks that more than 64k files can be added to an archive, @@ -112,13 +148,12 @@ content = zipf2.read("foo%08d" % i).decode('ascii') self.assertEqual(content, "%d" % (i**3 % 57)) zipf.close() - + def tearDown(self): support.unlink(TESTFN) - support.unlink(TESTFN2) def test_main(): - run_unittest(TestsWithSourceFile, OtherTests) + run_unittest(TestsWithSmallSourceFile, TestsWithHugeSourceFile, OtherTests) if __name__ == "__main__": test_main()