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

This commit is contained in:
Antoine Pitrou 2008-08-17 13:06:29 +00:00
parent 7f30a684c6
commit c53427087e

View 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