classification
Title: zipfile: AttributeError on extract
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: alter-bug-tracer, berker.peksag, gregory.p.smith, matrixise, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-05-21 12:26 by alter-bug-tracer, last changed 2019-09-12 14:33 by miss-islington.

Files
File name Uploaded Description Edit
attr0.zip alter-bug-tracer, 2019-05-21 12:26
Pull Requests
URL Status Linked Edit
PR 13632 merged berker.peksag, 2019-05-28 16:24
PR 16052 merged miss-islington, 2019-09-12 14:13
Messages (6)
msg343035 - (view) Author: alter-bug-tracer (alter-bug-tracer) * Date: 2019-05-21 12:26
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 <module>
    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 1677, in _extract_member
    with self.open(member, pwd=pwd) as source, \
  File "/usr/local/lib/python3.8/zipfile.py", line 1548, in open
    return ZipExtFile(zef_file, mode, zinfo, zd, True)
  File "/usr/local/lib/python3.8/zipfile.py", line 801, in __init__
    self._decompressor = _get_decompressor(self._compress_type)
  File "/usr/local/lib/python3.8/zipfile.py", line 708, in _get_decompressor
    return bz2.BZ2Decompressor()
AttributeError: 'NoneType' object has no attribute 'BZ2Decompressor'
msg343154 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-05-22 08:20
Hi, 

Thank you for your report

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

2. your file seems to have an issue.

 unzip attr0.zip 
Archive:  attr0.zip
  inflating: zipfile_extract.py      
  error:  invalid compressed data to inflate
 bad CRC 00000000  (should be 88075377)

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

I'm closing this issue.

Thank you
msg343155 - (view) Author: Stéphane Wirtel (matrixise) * (Python committer) Date: 2019-05-22 08:22
I also recommend that you read this document about the compilation and installation of Python and its dependencies.

https://devguide.python.org/setup/#compile-and-build

Thank you
msg343803 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2019-05-28 16:25
The OP's report is valid and they already stated that the file is malformed. More importantly, this can be reproduced with a valid ZIP file as well.

The correct behavior is to get RuntimeError in this case.

_check_compression() needs to be called before _get_decompressor().

There is no issue when getting the compressor object because _check_compression() is called inside _writecheck().
msg352172 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2019-09-12 14:13
New changeset 2f1b857562b0f1601c9019db74c29b7d7e21ac9f by Gregory P. Smith (Berker Peksag) in branch 'master':
bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
https://github.com/python/cpython/commit/2f1b857562b0f1601c9019db74c29b7d7e21ac9f
msg352178 - (view) Author: miss-islington (miss-islington) Date: 2019-09-12 14:33
New changeset 717cc61ed103684b8c73e0e8af10ace345f39f16 by Miss Islington (bot) in branch '3.8':
bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
https://github.com/python/cpython/commit/717cc61ed103684b8c73e0e8af10ace345f39f16
History
Date User Action Args
2019-09-12 14:33:56miss-islingtonsetnosy: + miss-islington
messages: + msg352178
2019-09-12 14:13:56miss-islingtonsetkeywords: + patch
pull_requests: + pull_request15674
2019-09-12 14:13:47gregory.p.smithsetmessages: + msg352172
2019-09-12 14:07:08gregory.p.smithsetassignee: gregory.p.smith

nosy: + gregory.p.smith
versions: + Python 3.9
2019-06-01 16:20:23berker.peksaglinkissue36992 superseder
2019-05-28 16:25:32berker.peksagsetstatus: closed -> open

components: + Library (Lib)

nosy: + berker.peksag, serhiy.storchaka
messages: + msg343803
resolution: not a bug ->
stage: resolved -> patch review
2019-05-28 16:24:27berker.peksagsetpull_requests: + pull_request13532
2019-05-22 08:22:27matrixisesetmessages: + msg343155
2019-05-22 08:20:22matrixisesetstatus: open -> closed

nosy: + matrixise
messages: + msg343154

resolution: not a bug
stage: resolved
2019-05-21 12:26:42alter-bug-tracercreate