Skip to content

Contrary to documentation, ZipFile.extract does not extract timestamps or other metadata #76351

Open

Description

@mhsmith
BPO 32170
Nosy @Yhg1s, @serhiy-storchaka, @mhsmith

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 2017-11-29.19:51:55.568>
labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
title = 'Contrary to documentation, ZipFile.extract does not extract timestamps or other metadata'
updated_at = <Date 2021-10-22.14:00:13.743>
user = 'https://github.com/mhsmith'

bugs.python.org fields:

activity = <Date 2021-10-22.14:00:13.743>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2017-11-29.19:51:55.568>
creator = 'Malcolm Smith'
dependencies = []
files = []
hgrepos = []
issue_num = 32170
keywords = []
message_count = 2.0
messages = ['307255', '307275']
nosy_count = 5.0
nosy_names = ['twouters', 'alanmcintyre', 'sascha_silbe', 'serhiy.storchaka', 'Malcolm Smith']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue32170'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

Linked PRs

Activity

  1. mhsmith commented on Nov 29, 2017

    @mhsmith
    MemberAuthor

    The documentation explicitly says "file information is extracted as accurately as possible". But the zipfile module doesn't actually extract any metadata at all. I assume this text was copied and pasted from the tarfile module, which does implement this.

    Fixing the code is preferred to fixing the documentation.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Nov 29, 2017
  3. mhsmith commented on Nov 30, 2017

    @mhsmith
    MemberAuthor

    Related: bpo-15795

  4. transferred this issue fromon Apr 10, 2022
  5. danny0838 commented on Jul 26, 2026

    @danny0838
    Contributor

    Issued PR gh-154704 that adds the extractor parameter to ZipFile.extract() and ZipFile.extractall() to support customized file attribute restoration.

    I have reviewed the related issue (gh-59999) and PRs (gh-32289, gh-150061) and incorporated their strengths. This PR specifically addresses the following key areas:

    1. Timestamp restoration support: Previous PRs only handled permission restoration and ignored timestamps (mtime/atime).

    2. Directory restoration edge cases: Restoring directory permissions immediately upon creation creates issues—extracting subsequent files into a directory resets its modification time and will fail if the directory is not writable. The PR defers directory attribute restoration to prevent these conflicts, which is similar to how the tarfile module does.

    3. Backward compatibility: The default behavior of ZipFile.extract() and ZipFile.extractall() remains unchanged. Different behavior is only triggered when a custom extractor is explicitly provided.

    4. Flexibility and extensibility: File attribute restoration during extraction can be complex, especially with extra fields, symlinks, overlapping paths (e.g., entry/ and entry or foo/bar.txt and foo), or unexpected I/O errors. Rather than trying to cover every edge case out-of-the-box, providing an extractor base class makes it straightforward for users to implement custom restoration order, error recovery, or cleanup logic.

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

    3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions