From: Serhiy Storchaka Date: Thu, 31 Jan 2013 13:30:36 +0000 (+0200) Subject: Issue #4844: ZipFile now raises BadZipFile when opens a ZIP file with an X-Git-Tag: v3.4.0a1~1491 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=db58e15ee55c66fd4900be2ab2e02b864ae2313e;p=python Issue #4844: ZipFile now raises BadZipFile when opens a ZIP file with an incomplete "End of Central Directory" record. Original patch by Guilherme Polo and Alan McIntyre. --- db58e15ee55c66fd4900be2ab2e02b864ae2313e diff --cc Lib/zipfile.py index 64f9092d12,235b811c19..509cba9789 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@@ -238,10 -242,12 +242,12 @@@ def _EndRecData(fpin) # file if this is the case). try: fpin.seek(-sizeEndCentDir, 2) - except IOError: + except OSError: return None data = fpin.read() - if data[0:4] == stringEndArchive and data[-2:] == b"\000\000": + if (len(data) == sizeEndCentDir and + data[0:4] == stringEndArchive and + data[-2:] == b"\000\000"): # the signature is correct and there's no comment, unpack structure endrec = struct.unpack(structEndArchive, data) endrec=list(endrec)