]> granicus.if.org Git - python/commitdiff
Issue #4844: ZipFile now raises BadZipFile when opens a ZIP file with an
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 31 Jan 2013 13:30:36 +0000 (15:30 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 31 Jan 2013 13:30:36 +0000 (15:30 +0200)
incomplete "End of Central Directory" record.  Original patch by Guilherme
Polo and Alan McIntyre.

1  2 
Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS

Simple merge
diff --cc Lib/zipfile.py
index 64f9092d124dc4ffb832d30ec38ba6734a0b3d27,235b811c19285796bf9d067f3cb8bc63fc7f895f..509cba9789539f35e45564e227de3428a9b13641
@@@ -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)
diff --cc Misc/NEWS
Simple merge