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.ZipInfo slots can raise unexpected AttributeError #70373

Closed
MatthewZipay mannequin opened this issue Jan 23, 2016 · 4 comments
Closed

zipfile.ZipInfo slots can raise unexpected AttributeError #70373

MatthewZipay mannequin opened this issue Jan 23, 2016 · 4 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@MatthewZipay
Copy link
Mannequin

MatthewZipay mannequin commented Jan 23, 2016

BPO 26185
Nosy @Yhg1s, @ned-deily, @DinoV, @takluyver, @serhiy-storchaka, @BoboTiG
PRs
  • bpo-26185: Fix repr() on empty ZipInfo object #13441
  • Files
  • zipfile.ZipInfo.patch: patch of Lib/zipfile.py and Lib/test/test_zipfile.py
  • 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 = None
    closed_at = <Date 2020-08-02.21:21:02.062>
    created_at = <Date 2016-01-23.10:41:53.478>
    labels = ['type-bug', 'library', '3.9']
    title = 'zipfile.ZipInfo slots can raise unexpected AttributeError'
    updated_at = <Date 2020-08-02.21:21:02.057>
    user = 'https://bugs.python.org/MatthewZipay'

    bugs.python.org fields:

    activity = <Date 2020-08-02.21:21:02.057>
    actor = 'ned.deily'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-08-02.21:21:02.062>
    closer = 'ned.deily'
    components = ['Library (Lib)']
    creation = <Date 2016-01-23.10:41:53.478>
    creator = 'Matthew Zipay'
    dependencies = []
    files = ['41698']
    hgrepos = []
    issue_num = 26185
    keywords = ['patch']
    message_count = 4.0
    messages = ['258859', '351452', '374694', '374697']
    nosy_count = 8.0
    nosy_names = ['twouters', 'alanmcintyre', 'ned.deily', 'dino.viehland', 'takluyver', 'serhiy.storchaka', 'Matthew Zipay', 'Tiger-222']
    pr_nums = ['13441']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26185'
    versions = ['Python 3.9']

    @MatthewZipay
    Copy link
    Mannequin Author

    MatthewZipay mannequin commented Jan 23, 2016

    The zipfile.ZipInfo.__init__ method permits several of ZipInfo's slot attributes to go uninitialized unless the object is obtained from ZipFile.getinfo() or ZipFile.infolist().

    As a result, accessing those attributes (header_offset, CRC, compress_size, or file_size) or attempting to repr() a ZipInfo object can fail unexpectedly with AttributeError. (I say "unexpectedly" because ZipInfo.__init__ and its attributes are public/documented, so the attributes ought to be properly initialized regardless of how the object gets created.)

    A simple test to illustrate:

    >>> import zipfile
    >>> zinfo = zipfile.ZipInfo()
    >>> repr(zinfo)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "********/cpython/Lib/zipfile.py", line 376, in __repr__
        result.append(' file_size=%r' % self.file_size)
    AttributeError: file_size

    (If you assign zinfo.file_size = None, it next fails on compress_size.)

    This problem has been noted before - see issues 3039 and 22217 - but has not been resolved.

    Patch including tests is attached.

    @MatthewZipay MatthewZipay mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 23, 2016
    @DinoV
    Copy link
    Contributor

    DinoV commented Sep 9, 2019

    New changeset 992347d by Dino Viehland (Mickaël Schoentgen) in branch 'master':
    bpo-26185: Fix repr() on empty ZipInfo object (bpo-13441)
    992347d

    @BoboTiG
    Copy link
    Mannequin

    BoboTiG mannequin commented Aug 2, 2020

    The ticket could be closed, right? The fix was merged quite some time ago.

    @ned-deily
    Copy link
    Member

    Fixed in 3.9.0

    @ned-deily ned-deily added the 3.9 only security fixes label Aug 2, 2020
    @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.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

    2 participants