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

Created on 2019-05-21 12:26 by alter-bug-tracer, last changed 2021-06-27 01:17 by gregory.p.smith. This issue is now closed.

File name Uploaded Description Edit 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 (7)
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():

Traceback (most recent call last):
  File "", line 6, in <module>
  File "/usr/local/lib/python3.8/", line 1607, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/local/lib/python3.8/", line 1677, in _extract_member
    with, pwd=pwd) as source, \
  File "/usr/local/lib/python3.8/", line 1548, in open
    return ZipExtFile(zef_file, mode, zinfo, zd, True)
  File "/usr/local/lib/python3.8/", line 801, in __init__
    self._decompressor = _get_decompressor(self._compress_type)
  File "/usr/local/lib/python3.8/", 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

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.

  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.

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)
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)
msg396472 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-24 11:54
This seems resolved, can we close?
Date User Action Args
2021-06-27 01:17:56gregory.p.smithsetstatus: pending -> closed
stage: patch review -> resolved
2021-06-24 11:54:51iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg396472

resolution: fixed
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 -> (no value)
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