GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Feature: provide (safe) traversal/extraction facilities for `zipfile.Path` · Issue #123727 · python/cpython

Feature: provide (safe) traversal/extraction facilities for zipfile.Path #123727

New issue
Copy link
New issue
Copy link
Open
Open
Feature: provide (safe) traversal/extraction facilities for zipfile.Path#123727
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@jaraco
jaraco
opened on Sep 5, 2024
Issue body actions

zipfile.Path could provide its own traversal that could offer some safety checks.

Something like that might be nice. Though perhaps it could be more generic instead of being part of zipfile.Path, even if zipfile.Path would then perhaps provide an extraction API using that?

Originally posted by @obfusk in #123270 (comment)

Activity

  1. jaraco
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Sep 5, 2024
  2. jaraco
    changed the title [-]Feature: provide (safe) traversal facilities for `zipfile.Path`[/-] [+]Feature: provide (safe) traversal/extraction facilities for `zipfile.Path`[/+] on Sep 5, 2024
  3. jaraco commented on Sep 5, 2024

    @jaraco
    jaraco
    on Sep 5, 2024
    MemberAuthor
    More actions

    As mentioned in that issue, there does already exist one extraction API in importlib.resources.as_file, although that implementation is written to create a temporary context. It also has certain limitations, such as it can extract a single file or directory, but not a set of files in a directory, and there's no facility to filter content in subdirectories.

    One thing to be careful about when extracting is that using mkdir(exists_ok=True) could lead to traversal outside the target directory (e.g. if the zip file contains ../../../etc/passwd).

    Before we embark on any implementation, let's first capture what are the motivations, use-cases, and requirements for such a feature? Who would use it and how?

    Reacted by FC (Fay) Stegerman
  4. picnixz
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Sep 5, 2024
  5. picnixz
    added this to Zipfile issues 📦on Sep 5, 2024
  6. rruuaanng commented on Sep 7, 2024

    @rruuaanng
    rruuaanng
    on Sep 7, 2024
    Contributor
    More actions

    For example, returning a list after calling, right?

  7. jaraco commented on Sep 7, 2024

    @jaraco
    jaraco
    on Sep 7, 2024
    MemberAuthor
    More actions

    Perhaps. We're looking for more complete user stories. For example:

    • A user has a zipfile.Path to a subdirectory of some zip file in memory that they downloaded from an online source. They wish to extract the contents of that directory to an existing directory on the file system. The existing directory might also contain other contents, which should be merged with the extracted contents. Extracted files should overwrite any existing files, but any existing subdirectories should be merged. The user does not expect any file names to overlap with directory names (such a case would be an error). At the end, the user wants a list of pathlib.Path objects for all files created and directories touched during the extraction.

    That's a contrived user story as an illustration. What I want are real user stories from users who have legitimate use-cases that aren't met by the current zipfile.Path and importlib.resources.as_file functionality.

    Reacted by FC (Fay) Stegerman
  8. obfusk commented on Sep 7, 2024

    @obfusk
    obfusk
    on Sep 7, 2024
    Contributor
    More actions

    Being able to combine .glob() and extract seems potentially useful to me.

    FYI: I just noticed .glob() does not seem to be documented.

  9. jaraco commented on Mar 8, 2025

    @jaraco
    jaraco
    on Mar 8, 2025
    MemberAuthor
    More actions

    If someone implements such a thing, let's not forget to remove the (recently contributed) note in the docs.

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

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

    Projects

    • Zipfile issues 📦
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402520 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.