New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zipfile: tuple IndexError on extract #81174
Comments
The following code throws an IndexError when attempting to extract a malformed archive (attached): import zipfile
import sys
zf = zipfile.ZipFile(sys.argv[1])
for info in zf.infolist():
zf.extract(info.filename) Result:
Traceback (most recent call last):
File "code.py", line 4, in <module>
zf = zipfile.ZipFile(sys.argv[1])
File "/usr/local/lib/python3.8/zipfile.py", line 1230, in __init__
self._RealGetContents()
File "/usr/local/lib/python3.8/zipfile.py", line 1353, in _RealGetContents
x._decodeExtra()
File "/usr/local/lib/python3.8/zipfile.py", line 480, in _decodeExtra
self.file_size = counts[idx]
IndexError: tuple index out of range |
unzip index_tuple.zip -x caution: zipfile comment truncated I think the issue is not with Python but with your ZIP file. Did you try to uncompress it with unzip?\ Thank you |
This report is valid. Serhiy has improved error reporting of the extra field in feccdb2. counts can indeed be an empty tuple:
If I'm reading section 4.5.3 of https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT correctly, I think we need to raise BadZipFile if ln == 0. |
It is not enough. IndexError can be raised for ln == 8 or 16 when file_size, compress_size and header_offset are all set to 0xffffffff. |
@alter-bug-tracer, could you please create test files for the cases Serhiy has just mentioned? |
@berker.peksag, first of all sorry for the late reply. |
I've pushed a PR which adds a test that generates corrupt zip64 files with different combinations of zip64 extra data lengths and zip64 flags (which determines how many fields are required in the extra data). It now raises a BadZipFile with a message naming the first missing field. |
Thank you for your contribution Daniel. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: