[issue39064] ValueError in zipfile.ZipFile
Sam Ezeh
report at bugs.python.org
Sun Apr 3 14:11:13 EDT 2022
Sam Ezeh <sam.z.ezeh at gmail.com> added the comment:
One way of doing this is by making the central directory offset negative by first taking the zip file containing just an EOCD record and then listing the total size of the central directory records as positive.
```
Python 3.11.0a4+ (heads/bpo-39064:eb1935dacf, Apr 3 2022, 19:09:53) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zipfile
>>> import io
>>> b = [80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> b[12] = 1
>>> f = io.BytesIO(bytes(b))
>>> zipfile.ZipFile(f)
Traceback (most recent call last):
File "/run/media/sam/OS/Git/cpython/Lib/zipfile.py", line 1370, in _RealGetContents
fp.seek(self.start_dir, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: negative seek value -1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/run/media/sam/OS/Git/cpython/Lib/zipfile.py", line 1284, in __init__
self._RealGetContents()
^^^^^^^^^^^^^^^^^^^^^^^
File "/run/media/sam/OS/Git/cpython/Lib/zipfile.py", line 1372, in _RealGetContents
raise BadZipFile("Bad offset for central directory")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
zipfile.BadZipFile: Bad offset for central directory
>>>
```
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39064>
_______________________________________
More information about the Python-bugs-list
mailing list