[Python-checkins] r65761 - python/trunk/Lib/zipfile.py

antoine.pitrou python-checkins at python.org
Sun Aug 17 15:06:29 CEST 2008


Author: antoine.pitrou
Date: Sun Aug 17 15:06:29 2008
New Revision: 65761

Log:
fix ZipFile.testzip() to work with very large embedded files



Modified:
   python/trunk/Lib/zipfile.py

Modified: python/trunk/Lib/zipfile.py
==============================================================================
--- python/trunk/Lib/zipfile.py	(original)
+++ python/trunk/Lib/zipfile.py	Sun Aug 17 15:06:29 2008
@@ -807,9 +807,14 @@
 
     def testzip(self):
         """Read all the files and check the CRC."""
+        chunk_size = 2 ** 20
         for zinfo in self.filelist:
             try:
-                self.read(zinfo.filename)       # Check CRC-32
+                # Read by chunks, to avoid an OverflowError or a
+                # MemoryError with very large embedded files.
+                f = self.open(zinfo.filename, "r")
+                while f.read(chunk_size):     # Check CRC-32
+                    pass
             except BadZipfile:
                 return zinfo.filename
 


More information about the Python-checkins mailing list