Skip to content
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: AttributeError on extract #81172

Closed
alter-bug-tracer mannequin opened this issue May 21, 2019 · 7 comments
Closed

zipfile: AttributeError on extract #81172

alter-bug-tracer mannequin opened this issue May 21, 2019 · 7 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@alter-bug-tracer
Copy link
Mannequin

alter-bug-tracer mannequin commented May 21, 2019

BPO 36991
Nosy @gpshead, @berkerpeksag, @serhiy-storchaka, @matrixise, @miss-islington, @alter-bug-tracer, @iritkatriel
PRs
  • bpo-36991: Fix incorrect exception escaping ZipFile.extract() #13632
  • [3.8] bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632) #16052
  • Files
  • attr0.zip
  • 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:

    assignee = 'https://github.com/gpshead'
    closed_at = <Date 2021-06-27.01:17:56.751>
    created_at = <Date 2019-05-21.12:26:42.365>
    labels = ['3.8', 'type-bug', 'library', '3.9']
    title = 'zipfile: AttributeError on extract'
    updated_at = <Date 2021-06-27.01:17:56.751>
    user = 'https://github.com/alter-bug-tracer'

    bugs.python.org fields:

    activity = <Date 2021-06-27.01:17:56.751>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2021-06-27.01:17:56.751>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2019-05-21.12:26:42.365>
    creator = 'alter-bug-tracer'
    dependencies = []
    files = ['48346']
    hgrepos = []
    issue_num = 36991
    keywords = ['patch']
    message_count = 7.0
    messages = ['343035', '343154', '343155', '343803', '352172', '352178', '396472']
    nosy_count = 7.0
    nosy_names = ['gregory.p.smith', 'berker.peksag', 'serhiy.storchaka', 'matrixise', 'miss-islington', 'alter-bug-tracer', 'iritkatriel']
    pr_nums = ['13632', '16052']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36991'
    versions = ['Python 3.8', 'Python 3.9']

    @alter-bug-tracer
    Copy link
    Mannequin Author

    alter-bug-tracer mannequin commented May 21, 2019

    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'

    @alter-bug-tracer alter-bug-tracer mannequin added 3.8 only security fixes type-bug An unexpected behavior, bug, or error labels May 21, 2019
    @matrixise
    Copy link
    Member

    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 0000000 (should be 88075377)

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

    I'm closing this issue.

    Thank you

    @matrixise
    Copy link
    Member

    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

    @berkerpeksag
    Copy link
    Member

    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().

    @berkerpeksag berkerpeksag added the stdlib Python modules in the Lib dir label May 28, 2019
    @berkerpeksag berkerpeksag reopened this May 28, 2019
    @gpshead gpshead added the 3.9 only security fixes label Sep 12, 2019
    @gpshead gpshead self-assigned this Sep 12, 2019
    @gpshead
    Copy link
    Member

    gpshead commented Sep 12, 2019

    New changeset 2f1b857 by Gregory P. Smith (Berker Peksag) in branch 'master':
    bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
    2f1b857

    @miss-islington
    Copy link
    Contributor

    New changeset 717cc61 by Miss Islington (bot) in branch '3.8':
    bpo-36991: Fix incorrect exception escaping ZipFile.extract() (GH-13632)
    717cc61

    @iritkatriel
    Copy link
    Member

    This seems resolved, can we close?

    @gpshead gpshead closed this as completed Jun 27, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants