]> granicus.if.org Git - python/commitdiff
fix ZipFile.testzip() to work with very large embedded files
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 17 Aug 2008 13:06:29 +0000 (13:06 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 17 Aug 2008 13:06:29 +0000 (13:06 +0000)
Lib/zipfile.py

index 609dea3f273d7db5866c705e38f1511a6cbb694b..ac17177e9c3f9bf37852b3bb0169afaf9277a041 100644 (file)
@@ -807,9 +807,14 @@ class ZipFile:
 
     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