You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Contrary to documentation, ZipFile.extract does not extract timestamps or other metadata #76351
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=Noneclosed_at=Nonecreated_at=<Date2017-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=<Date2021-10-22.14:00:13.743>user='https://github.com/mhsmith'
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.
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:
Timestamp restoration support: Previous PRs only handled permission restoration and ignored timestamps (mtime/atime).
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.
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.
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.
Activity
mhsmith commentedon Nov 29, 2017
The documentation explicitly says "file information is extracted as accurately as possible". But the
zipfilemodule doesn't actually extract any metadata at all. I assume this text was copied and pasted from thetarfilemodule, which does implement this.Fixing the code is preferred to fixing the documentation.
mhsmith commentedon Nov 30, 2017
Related: bpo-15795
danny0838 commentedon Jul 26, 2026
Issued PR gh-154704 that adds the
extractorparameter toZipFile.extract()andZipFile.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:
Timestamp restoration support: Previous PRs only handled permission restoration and ignored timestamps (mtime/atime).
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
tarfilemodule does.Backward compatibility: The default behavior of
ZipFile.extract()andZipFile.extractall()remains unchanged. Different behavior is only triggered when a customextractoris explicitly provided.Flexibility and extensibility: File attribute restoration during extraction can be complex, especially with extra fields, symlinks, overlapping paths (e.g.,
entry/andentryorfoo/bar.txtandfoo), 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.