Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Lib/test/test_zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,20 @@ def test_seek_tell(self):
fp.seek(0, os.SEEK_SET)
self.assertEqual(fp.tell(), 0)

def test_malformatted_zip64_extra_field(self):
zipdata = (
b'PK\x03\x04\xfb\x03PK\x01\x02\x1e\xfb\x13\x00\x00\x00\xd3'
b'\x00\x978\xa2NwS\x17\x88\xfa\x00\x00\x00\xff\xff\xff\xff'
b'\x12\x00\x18\x00\x00\x00\x00\x00\x01\x00\x00\x00\xb4\x81'
b'\x00\x00\x00\x00zipfile_extract/\x00\x00'
# Start of the extra field.
b'\x01\x00\x00\x00//(///\xff\x00\x00\x00//////\xe8\x03\x00 '
b'PK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00X\x00\x00\x00F'
b'\x01\x00\xee\xff\x01'
)
with self.assertRaises(zipfile.BadZipFile):
zipfile.ZipFile(io.BytesIO(zipdata))

def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
Expand Down
3 changes: 1 addition & 2 deletions Lib/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,14 @@ def _decodeExtra(self):
tp, ln = unpack('<HH', extra[:4])
if ln+4 > len(extra):
raise BadZipFile("Corrupt extra field %04x (size=%d)" % (tp, ln))
# Zip64 extended information extra field
if tp == 0x0001:
if ln >= 24:
counts = unpack('<QQQ', extra[4:28])
elif ln == 16:
counts = unpack('<QQ', extra[4:20])
elif ln == 8:
counts = unpack('<Q', extra[4:12])
elif ln == 0:
counts = ()
else:
raise BadZipFile("Corrupt extra field %04x (size=%d)" % (tp, ln))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve error detection of malformed extra field in
:class:`zipfile.ZipFile`.