Title: shutil.unpack_archive() on Windows writes outside extract_dir for ZIP entries with drive-prefixed names · Issue #146581 · python/cpython · GitHub
Open Graph Title: shutil.unpack_archive() on Windows writes outside extract_dir for ZIP entries with drive-prefixed names · Issue #146581 · python/cpython
X Title: shutil.unpack_archive() on Windows writes outside extract_dir for ZIP entries with drive-prefixed names · Issue #146581 · python/cpython
Description: Bug report Bug description: Summary I found a Windows-specific issue in shutil.unpack_archive() when extracting ZIP files. In Lib/shutil.py, the private helper _unpack_zipfile() skips names that start with / or contain .., but it does no...
Open Graph Description: Bug report Bug description: Summary I found a Windows-specific issue in shutil.unpack_archive() when extracting ZIP files. In Lib/shutil.py, the private helper _unpack_zipfile() skips names that st...
X Description: Bug report Bug description: Summary I found a Windows-specific issue in shutil.unpack_archive() when extracting ZIP files. In Lib/shutil.py, the private helper _unpack_zipfile() skips names that st...
Opengraph URL: https://github.com/python/cpython/issues/146581
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"shutil.unpack_archive() on Windows writes outside extract_dir for ZIP entries with drive-prefixed names","articleBody":"# Bug report\n\n### Bug description:\n\n### Summary\n\nI found a Windows-specific issue in `shutil.unpack_archive()` when extracting ZIP files.\n\nIn `Lib/shutil.py`, the private helper `_unpack_zipfile()` skips names that start with `/` or contain `..`, but it does not reject or sanitize Windows drive-prefixed names such as `D:/path/file`.\n\nOn Windows, such names are joined into a drive-qualified path and can escape the intended extraction directory. As a result, a crafted ZIP archive can cause files to be written outside `extract_dir`.\n\n### Affected component\n\n- `Lib/shutil.py`\n- `_unpack_zipfile()`\n\n### Impact\n\nA crafted ZIP archive can cause an arbitrary file write outside `extract_dir` on Windows.\n\n### Trigger condition\n\n- Platform: Windows\n- Archive format: ZIP\n- A ZIP entry name contains a drive prefix such as `D:/...`\n- `extract_dir` is on a different drive\n\n### Tested environment\n\nI reproduced this on Windows with Python 3.12.8.\n\n### Minimal reproduction\n\nI attached a minimal repro script:\n\n- `repro_shutil_unpack_zip_windows_drive_path_min.py`\n\nThe repro creates a ZIP archive containing an entry like:\n\nD:/shutil_outside_min.txt\n\nand then calls:\n\nshutil.unpack_archive(str(zip_path), str(extract_dir))\nWith extract_dir on another drive, the file is written outside the intended extraction directory.\n\nRoot cause\nThe validation in _unpack_zipfile() appears incomplete for Windows path semantics. Checking only for leading / and .. is not sufficient, because drive-prefixed paths such as D:/... are still treated as rooted or drive-qualified paths by Windows path handling.\n\nFor comparison, zipfile's own extraction logic strips drive information before extraction, but shutil._unpack_zipfile() does not.\n\nExpected behavior\nZIP entries that are absolute, drive-prefixed, or otherwise resolve outside extract_dir on Windows should be rejected or normalized so that extraction always remains within extract_dir.\n\nActual behavior\nA crafted ZIP entry with a drive prefix can escape extract_dir and be written to another location.\n\nAdditional context\nI previously reported this privately to the Python Security Response Team on March 28, 2026, but I have not received a response yet, so I am opening this issue for tracking and triage.\n\nI also attached a short write-up:\n\nvuln_shutil_unpack_archive_zip_windows_drive_path.md\n\n[shutil_unpack_archive_zip_windows_drive_path_min.zip](https://github.com/user-attachments/files/26325208/shutil_unpack_archive_zip_windows_drive_path_min.zip)\n\n### CPython versions tested on:\n\nCPython main branch, 3.14\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146588\n* gh-146591\n* gh-149064\n* gh-149065\n* gh-149066\n* gh-149071\n* gh-149994\n* gh-150064\n* gh-150065\n* gh-150066\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/PuH4ck3rX","@type":"Person","name":"PuH4ck3rX"},"datePublished":"2026-03-28T17:55:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/146581/cpython/issues/146581"}
| 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:cd1a79c1-7321-94d9-6394-8b7bf188ede5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3DE:3FE40B:CA1572:1139F50:6A55B3A8 |
| html-safe-nonce | 1a37fcb4d94b242251c79a16487be545b66334aa2b0373b07aa861c0f0623036 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0RFOjNGRTQwQjpDQTE1NzI6MTEzOUY1MDo2QTU1QjNBOCIsInZpc2l0b3JfaWQiOiI3OTc2NDI2ODc5NTE0NDI0MjMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 64843583d06b64baef153d93c78e3ba05920287f82c2070f63a6526240798dab |
| hovercard-subject-tag | issue:4161096240 |
| 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/146581/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a326f3ddca96f1503e75688d65a695435c41e52443d85979ab7f166967de037d/python/cpython/issues/146581 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a326f3ddca96f1503e75688d65a695435c41e52443d85979ab7f166967de037d/python/cpython/issues/146581 |
| og:image:alt | Bug report Bug description: Summary I found a Windows-specific issue in shutil.unpack_archive() when extracting ZIP files. In Lib/shutil.py, the private helper _unpack_zipfile() skips names that st... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | PuH4ck3rX |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | 653fccf1e27344851c0d3de3fa6faa526197f072 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width