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 does not supports Unicode Path Extra Field (0x7075) zip header field #86094

Closed
ivansorokintech mannequin opened this issue Oct 4, 2020 · 3 comments
Closed

ZipFile does not supports Unicode Path Extra Field (0x7075) zip header field #86094

ivansorokintech mannequin opened this issue Oct 4, 2020 · 3 comments
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ivansorokintech
Copy link
Mannequin

ivansorokintech mannequin commented Oct 4, 2020

BPO 41928
Nosy @agiudiceandrea
PRs
  • bpo-41928: Add support for Unicode Path Extra Field in ZipFile #23736
  • Files
  • 23.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 = None
    closed_at = None
    created_at = <Date 2020-10-04.11:21:41.399>
    labels = ['type-feature', 'library', '3.10']
    title = 'ZipFile does not supports Unicode Path Extra Field (0x7075) zip header field'
    updated_at = <Date 2021-01-22.01:30:26.942>
    user = 'https://bugs.python.org/ivansorokintech'

    bugs.python.org fields:

    activity = <Date 2021-01-22.01:30:26.942>
    actor = 'andreaerdna'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-10-04.11:21:41.399>
    creator = 'ivan.sorokin.tech'
    dependencies = []
    files = ['49491']
    hgrepos = []
    issue_num = 41928
    keywords = ['patch']
    message_count = 3.0
    messages = ['377931', '377945', '385467']
    nosy_count = 2.0
    nosy_names = ['ivan.sorokin.tech', 'andreaerdna']
    pr_nums = ['23736']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41928'
    versions = ['Python 3.10']

    Linked PRs

    @ivansorokintech
    Copy link
    Mannequin Author

    ivansorokintech mannequin commented Oct 4, 2020

    See attached sample. Well-known unzip command line tool lists its contents correctly:

    $ unzip -l 23.zip
    Archive:  23.zip
      Length      Date    Time    Name
    ---------  ---------- -----   

    81408  2012-10-23 19:03   Β' ΦΑΣΗ ΠΕ06 ΣΧΟΛΕΙΑ ΕΑΕΠ (ΙΝΤ).xls
    

    --------- -------
    81408 1 file

    But ZipFile lists the same file inside this archive as
    ü' öÇæå Åä06 æòÄèäêÇ äÇäÅ (êîÆ).xls

    It's because ZipFile completely ignores Unicode Path Extra Field (0x7075) zip header field.

    See .ZIP specification for details on this field meaning and usage:
    https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT

    @ivansorokintech ivansorokintech mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 4, 2020
    @ivansorokintech
    Copy link
    Mannequin Author

    ivansorokintech mannequin commented Oct 4, 2020

    Grand unified algorithm to read filenames from zip files correctly:

    1. Do zip entry have «Unicode Path Extra Field» (0x7075)? Use it for file name.
    2. Is Unicode flag (0x800) set in «Flags» Field of zip entry? Assume «Filename» Field is in UTF-8.
    3. Do «HostOS» Field of zip entry have values of 0 (FAT) or 11 (NTFS)? Assume «Filename» Field is in OEM charset corresponding to system locale.
    4. Assume «Filename» Field is in UTF-8.

    p7zip with oemcp patch (https://github.com/unxed/oemcp/) uses exactly this method, and is able to process all zip files in my test set correctly (my test set contains several zips generated by different packers on windows, macos, linux, and by online services). The same algorithm should be used in any zip unpacker wishing to process non-latin filenames as gently as possible.

    @agiudiceandrea
    Copy link
    Mannequin

    agiudiceandrea mannequin commented Jan 22, 2021

    I submitted more than a month ago a PR that adds support for Unicode Path Extra Field in ZipFile.
    The PR #23736 is awaiting a review in order to be merged.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @corona10 corona10 added 3.12 bugs and security fixes and removed 3.10 only security fixes labels Apr 5, 2023
    @corona10 corona10 closed this as completed Apr 5, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    Status: Done
    Development

    No branches or pull requests

    1 participant