This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IndexError exception on corrupted zip file
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: jvoisin, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2019-12-10 16:47 by jvoisin, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
crash-23b7d72644702df94bfcfaab4c25b01ff31c0b38 jvoisin, 2019-12-10 16:47
Messages (3)
msg358202 - (view) Author: jvoisin (jvoisin) Date: 2019-12-10 16:47
The attached file raises an `IndexError: tuple index out of range` exception when trying to open it with `zipfile.Zipfile('crash-23b7d72644702df94bfcfaab4c25b01ff31c0b38')`, with the following stacktrace:

```
$ cat test_zip.py
import zipfile
import sys

with zipfile.ZipFile(sys.argv[1]) as f:
  pass
$ python3 ./test_zip.py ./crash-23b7d72644702df94bfcfaab4c25b01ff31c0b38
Traceback (most recent call last):
  File "./test_zip.py", line 4, in <module>
    with zipfile.ZipFile(sys.argv[1]) as f:
  File "/usr/lib/python3.7/zipfile.py", line 1225, in __init__
    self._RealGetContents()
  File "/usr/lib/python3.7/zipfile.py", line 1348, in _RealGetContents
    x._decodeExtra()
  File "/usr/lib/python3.7/zipfile.py", line 480, in _decodeExtra
    self.file_size = counts[idx]
IndexError: tuple index out of range
$

```

The zipfile documentation doesn't mention that IndexError is a possible exception for this method.
msg358204 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-12-10 16:55
master produces the below error while 3.8.0 produces IndexError. I guess it's fixed by one of the reports.

./python ../backups/bpo39018.py ../crash-23b7d72644702df94bfcfaab4c25b01ff31c0b38
Traceback (most recent call last):
  File "/home/xtreak/stuff/python/cpython/../backups/bpo39018.py", line 4, in <module>
    with zipfile.ZipFile(sys.argv[1]) as f:
  File "/home/xtreak/stuff/python/cpython/Lib/zipfile.py", line 1256, in __init__
    self._RealGetContents()
  File "/home/xtreak/stuff/python/cpython/Lib/zipfile.py", line 1379, in _RealGetContents
    x._decodeExtra()
  File "/home/xtreak/stuff/python/cpython/Lib/zipfile.py", line 483, in _decodeExtra
    raise BadZipFile(f"Corrupt zip64 extra field. "
zipfile.BadZipFile: Corrupt zip64 extra field. File size not found.
msg358206 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-12-10 16:58
Bisecting gives me the commit as da6ce58dd5ac109485af45878fca6bfd265b43e9 where exception message is improved with issue36993
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83199
2019-12-10 17:19:43serhiy.storchakasetstatus: open -> closed
resolution: out of date
stage: resolved
2019-12-10 16:58:53xtreaksetnosy: + serhiy.storchaka
messages: + msg358206
2019-12-10 16:55:53xtreaksetnosy: + xtreak
messages: + msg358204
2019-12-10 16:47:07jvoisincreate