Skip to content

zipfile.ZipFile().extractall() header mismatch for non-ASCII characters #55010

Closed

Description

@MZ
mannequin
BPO 10801
Nosy @loewis, @birkenfeld, @amauryfa, @vstinner, @bitdancer
Files
  • bug_zipfile_extractall.zip: ZIP with three files that can reproduce the problem
  • zipfile.diff
  • issue10801_test.1.patch
  • 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 2011-01-01.12:16:56.320>
    created_at = <Date 2010-12-31.13:38:34.847>
    labels = ['type-bug', 'library']
    title = 'zipfile.ZipFile().extractall() header mismatch for non-ASCII characters'
    updated_at = <Date 2011-06-10.14:35:35.544>
    user = 'https://bugs.python.org/MZ'

    bugs.python.org fields:

    activity = <Date 2011-06-10.14:35:35.544>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-01-01.12:16:56.320>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2010-12-31.13:38:34.847>
    creator = 'M..Z.'
    dependencies = []
    files = ['20204', '20205', '20211']
    hgrepos = []
    issue_num = 10801
    keywords = ['patch']
    message_count = 18.0
    messages = ['124964', '124966', '124978', '124991', '124992', '124994', '124995', '124998', '124999', '125000', '135838', '136228', '136229', '136559', '136566', '136567', '136682', '138081']
    nosy_count = 9.0
    nosy_names = ['loewis', 'georg.brandl', 'amaury.forgeotdarc', 'vstinner', 'Arfrever', 'r.david.murray', 'eli.bendersky', 'M..Z.', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10801'
    versions = ['Python 3.2']

    Activity

    1. MZ commented on Dec 31, 2010

      MZmannequin
      MannequinAuthor

      Trying to unpack a ZIP file where some packet files contain danish letters results in:

      zipfile.BadZipFile: File name in directory 'filename_with_æoå.txt'
      and header b'filename_with_\x91o\x86.txt' differ.
      

      Using Py 3.2b2 on Win7.

      Unpack the attached ZIP file and run the Py script, which will show the problem using the enclosed two ZIP files.

    2. added
      stdlib
      type-bug
      on Dec 31, 2010
    3. loewis commented on Dec 31, 2010

      loewismannequin
      Mannequin

      The attached patch fixes it for me. No time to write tests right now.

    4. bitdancer commented on Dec 31, 2010

      @bitdancer
      Member

      FWIW, having just looked at related code in zipfile recently, this patch looks correct to me.

    5. elibendersky commented on Jan 1, 2011

      elibenderskymannequin
      Mannequin

      I'll try to produce a test in the next hour or two

    6. elibendersky commented on Jan 1, 2011

      elibenderskymannequin
      Mannequin

      I'm attaching a patch with a test for Martin's fix. I had trouble programmatically generating a "bad" zip for this bug, since it has different encodings for the header and filename (probably created by WinZip?). So I created a directory in test/ and placed the problematic zipfile M.Z. submitted in there, and wrote an appropriate test in test_zipfile.py

      I verified the test fails on py3k trunk before Martin's fix, and succeeds after it, both by running the test file directly and through regrtest.

      Note: Tested only on Ubuntu

    7. birkenfeld commented on Jan 1, 2011

      @birkenfeld
      Member

      Committed patch and test in r87604.

    8. birkenfeld commented on Jan 1, 2011

      @birkenfeld
      Member
    9. birkenfeld commented on Jan 1, 2011

      @birkenfeld
      Member

      OK, I think r87606 fixed it: it doesn't extract the files, instead calls only open().

    10. elibendersky commented on Jan 1, 2011

      elibenderskymannequin
      Mannequin

      Georg, did you figure out the root cause of the problem on that buildbot? Seeing it fails in open(targetpath, "wb"), extracting the file may have failed if the bot had no write permissions to the current directory, but the ascii encoding error is not what I'd expect in such a case.

    11. birkenfeld commented on Jan 1, 2011

      @birkenfeld
      Member

      Well, it looks like the filesystem encoding is set to ASCII on these machines.

    12. vstinner commented on May 12, 2011

      @vstinner
      Member

      Issue bpo-12048 is a duplicate of this bug, but with Python 3.1. Should we backport the fix to Python 3.1?

    13. python-dev commented on May 18, 2011

      python-devmannequin
      Mannequin

      New changeset 1f0f0e317873 by Victor Stinner in branch '3.1':
      Backport commit 33543b4e0e5d from Python 3.2: bpo-10801: In zipfile, support
      http://hg.python.org/cpython/rev/1f0f0e317873

    14. python-dev commented on May 18, 2011

      python-devmannequin
      Mannequin

      New changeset 243c78fbbb49 by Victor Stinner in branch '3.1':
      Ooops, add the missing file of the backport of commit 33543b4e0e5d from Python
      http://hg.python.org/cpython/rev/243c78fbbb49

    15. Arfrever commented on May 22, 2011

      Arfrevermannequin
      Mannequin

      These changes cause test failure on 3.1 branch when verbose mode is disabled:

      # python3.1 -m test.regrtest test_zipfile
      test_zipfile
      test test_zipfile produced unexpected output:


      *** line 2 of actual output doesn't appear in expected output after line 1:
      + /usr/lib64/python3.1/test/zip_cp437_header.zip


      1 test failed:
      test_zipfile

    16. python-dev commented on May 22, 2011

      python-devmannequin
      Mannequin

      New changeset 9ef8fc5454cb by Victor Stinner in branch '3.1':
      Issue bpo-10801: Remove a debug print() from test_zipfile
      http://hg.python.org/cpython/rev/9ef8fc5454cb

    17. vstinner commented on May 22, 2011

      @vstinner
      Member

      These changes cause test failure on 3.1 branch when verbose mode is disabled

      What a shame! I commited a debug "print()":
      1.39 + print(fname)

      It should be fixed by my last commit.

    18. birkenfeld commented on May 23, 2011

      @birkenfeld
      Member

      Victor: you should have a look at <http://bitbucket.org/birkenfeld/hgcodesmell\>.

    19. python-dev commented on Jun 10, 2011

      python-devmannequin
      Mannequin

      New changeset 33b7428e65b4 by Victor Stinner in branch '3.1':
      Issue bpo-10801: Fix test_unicode_filenames() of test_zipfile
      http://hg.python.org/cpython/rev/33b7428e65b4

    20. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions