Title: `zipfile.extractall` never restores stored Unix permissions · Issue #149839 · python/cpython · GitHub
Open Graph Title: `zipfile.extractall` never restores stored Unix permissions · Issue #149839 · python/cpython
X Title: `zipfile.extractall` never restores stored Unix permissions · Issue #149839 · python/cpython
Description: Bug report Bug description: ZipInfo.from_file stores the source file's Unix permissions in external_attr, but ZipFile._extract_member never reads them back. Extracted files are created with open(targetpath, "wb"), which applies the proce...
Open Graph Description: Bug report Bug description: ZipInfo.from_file stores the source file's Unix permissions in external_attr, but ZipFile._extract_member never reads them back. Extracted files are created with open(ta...
X Description: Bug report Bug description: ZipInfo.from_file stores the source file's Unix permissions in external_attr, but ZipFile._extract_member never reads them back. Extracted files are created with ope...
Opengraph URL: https://github.com/python/cpython/issues/149839
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`zipfile.extractall` never restores stored Unix permissions","articleBody":"# Bug report\n\n### Bug description:\n\n`ZipInfo.from_file` stores the source file's Unix permissions in `external_attr`, but `ZipFile._extract_member` never reads them back. Extracted files are created with `open(targetpath, \"wb\")`, which applies the process umask (typically `0o644`). (And there isn't an `os.chmod` afterwards.)\n\nThis means a zip archive containing a file at `0o600` will extract it world-readable. `tarfile` for example on the other hand [does apply](https://github.com/python/cpython/blob/c6f7368157ecf9f2cdd537d8b6fad6e011bce344/Lib/tarfile.py#L2636-L2640) those attributes after extracting; `zipfile` silently discards the permission metadata it recorded.\n\nThis could be fixed by applying the stored mode after writing:\n\n```py\nwith self.open(member, pwd=pwd) as source, open(targetpath, \"wb\") as target:\n shutil.copyfileobj(source, target)\n\nattr = member.external_attr \u003e\u003e 16\nif attr:\n os.chmod(targetpath, attr)\n```\n\nNote that this isn't perfect either, as this leaves window of exposure (similar to what was reported in #96719), but it is a different bug (permissions restored after a while vs. permissions not reset at all).\n\n_I have [this branch](https://github.com/python/cpython/compare/main...KowalskiThomas:cpython:kowalski/fix-restore-permissions-after-extracting-zip) which updates it (with a regression test on top)._\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-150061\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/KowalskiThomas","@type":"Person","name":"KowalskiThomas"},"datePublished":"2026-05-14T16:51:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/149839/cpython/issues/149839"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3f24928d-a222-d073-51d6-ac2a4b96aaa2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC26:1FFDFF:5A787AB:7F8C283:6A5012D6 |
| html-safe-nonce | 9027d3a02e218fb867262d172913291948157f855fb5445c989ea5bf04bf20a9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzI2OjFGRkRGRjo1QTc4N0FCOjdGOEMyODM6NkE1MDEyRDYiLCJ2aXNpdG9yX2lkIjoiNDAwMjczMjQ5OTE1NjM4NDg2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8f651d9e63f3da8b37bcb0477435836d9d61f0fdd1ea1a1f7212b268bda51f63 |
| hovercard-subject-tag | issue:4447684020 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/149839/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8f8d6d16a803ec3789649e690543c6230d19ba7075f22b4f20bb878ab9c804b2/python/cpython/issues/149839 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8f8d6d16a803ec3789649e690543c6230d19ba7075f22b4f20bb878ab9c804b2/python/cpython/issues/149839 |
| og:image:alt | Bug report Bug description: ZipInfo.from_file stores the source file's Unix permissions in external_attr, but ZipFile._extract_member never reads them back. Extracted files are created with open(ta... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KowalskiThomas |
| hostname | github.com |
| expected-hostname | github.com |
| None | fe4f38b24922a1ce81c1708c3793b47c185599b9144ab94f6ca846b00698058d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 42b6390c91978a16f9196c38c7a00e9bf21f37e7 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width