From: Antoine Pitrou Date: Sun, 17 Aug 2008 13:06:29 +0000 (+0000) Subject: fix ZipFile.testzip() to work with very large embedded files X-Git-Tag: v2.6b3~54 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c53427087e6fcf6680c83f7ede85ce02510c89a0;p=thirdparty%2FPython%2Fcpython.git fix ZipFile.testzip() to work with very large embedded files --- diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 609dea3f273d..ac17177e9c3f 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -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