Issue 36992: zipfile: AttributeError on extract (LZMA) (original) (raw)

The following code throws an AttributeError 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 6, in zf.extract(info.filename) File "/usr/local/lib/python3.8/zipfile.py", line 1607, in extract return self._extract_member(member, path, pwd) File "/usr/local/lib/python3.8/zipfile.py", line 1679, in _extract_member shutil.copyfileobj(source, target) File "/usr/local/lib/python3.8/shutil.py", line 198, in copyfileobj buf = fsrc_read(length) File "/usr/local/lib/python3.8/zipfile.py", line 903, in read data = self._read1(n) File "/usr/local/lib/python3.8/zipfile.py", line 986, in _read1 data = self._decompressor.decompress(data) File "/usr/local/lib/python3.8/zipfile.py", line 635, in decompress self._decomp = lzma.LZMADecompressor(lzma.FORMAT_RAW, filters=[ AttributeError: 'NoneType' object has no attribute 'LZMADecompressor'

Hi,

Thank you for your report

but do you have the lzma lib on your system, because without that, Python is not compiled with the support of this format.

example, with a debian docker image:

without all the needed libraries you would get this exception:

Python build finished successfully! The necessary bits to build these optional modules were not found: _bz2 _curses _curses_panel
_dbm _gdbm _hashlib
_lzma _sqlite3 _ssl
_tkinter _uuid readline
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

The following modules found by detect_modules() in setup.py, have been built by the Makefile instead, as configured by the Setup files: _abc atexit pwd
time

Failed to build these modules: _ctypes

Please could you check again your compilation step and retry with an other file.

I'm closing this issue but you are free to re-open it if you have tested with the right dependencies.

Thank you