From c53427087e6fcf6680c83f7ede85ce02510c89a0 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 17 Aug 2008 13:06:29 +0000 Subject: [PATCH] fix ZipFile.testzip() to work with very large embedded files --- Lib/zipfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 609dea3f273..ac17177e9c3 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