Title: tarfile extraction filters raise raw ValueError for Windows drive-relative paths · Issue #154987 · python/cpython · GitHub
Open Graph Title: tarfile extraction filters raise raw ValueError for Windows drive-relative paths · Issue #154987 · python/cpython
X Title: tarfile extraction filters raise raw ValueError for Windows drive-relative paths · Issue #154987 · python/cpython
Description: Bug report Bug description: tarfile extraction filters raise a raw ValueError on Windows when handling drive-relative member names or link targets such as C:bad.txt. This looks like an inconsistency in the extraction-filter error handlin...
Open Graph Description: Bug report Bug description: tarfile extraction filters raise a raw ValueError on Windows when handling drive-relative member names or link targets such as C:bad.txt. This looks like an inconsistenc...
X Description: Bug report Bug description: tarfile extraction filters raise a raw ValueError on Windows when handling drive-relative member names or link targets such as C:bad.txt. This looks like an inconsistenc...
Opengraph URL: https://github.com/python/cpython/issues/154987
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tarfile extraction filters raise raw ValueError for Windows drive-relative paths","articleBody":"# Bug report\n\n### Bug description:\n\n`tarfile` extraction filters raise a raw `ValueError` on Windows when handling drive-relative member names or link targets such as `C:bad.txt`.\n\nThis looks like an inconsistency in the extraction-filter error handling path. The affected cases are rejected through a raw `ValueError` from Windows path handling instead of the structured `tarfile` filter exceptions that similar rejected paths use.\n\nFor example, with `filter=\"data\"` and `errorlevel = 0`, I expected the invalid member to be skipped/refused and extraction to continue to later members. Instead, extraction aborts with:\n\n```text\nValueError: Paths don't have the same drive\n```\n\nMinimal reproducer:\n\n```python\nimport io\nimport os\nimport tarfile\nimport tempfile\nfrom pathlib import Path\n\n\ndef add_file(tf, name, data=b\"x\"):\n info = tarfile.TarInfo(name)\n info.size = len(data)\n tf.addfile(info, io.BytesIO(data))\n\n\ndef build_archive_with_drive_relative_member(path):\n with tarfile.open(path, \"w\") as tf:\n add_file(tf, \"before.txt\", b\"before\")\n add_file(tf, \"C:bad.txt\", b\"bad\")\n add_file(tf, \"after.txt\", b\"after\")\n\n\ndef main():\n if os.name != \"nt\":\n print(\"This reproducer is Windows-specific.\")\n return 0\n\n with tempfile.TemporaryDirectory() as tmp:\n tmp = Path(tmp)\n archive_path = tmp / \"drive_relative.tar\"\n extract_dir = tmp / \"extract\"\n extract_dir.mkdir()\n\n build_archive_with_drive_relative_member(archive_path)\n\n try:\n with tarfile.open(archive_path, \"r\") as tf:\n tf.errorlevel = 0\n tf.extractall(extract_dir, filter=\"data\")\n except Exception as exc:\n print(\"exception_type:\", type(exc).__name__)\n print(\"exception_message:\", str(exc))\n\n print(\"before_exists:\", (extract_dir / \"before.txt\").exists())\n print(\"after_exists:\", (extract_dir / \"after.txt\").exists())\n\n\nif __name__ == \"__main__\":\n raise SystemExit(main())\n```\n\nObserved output on Windows:\n\n```text\nexception_type: ValueError\nexception_message: Paths don't have the same drive\nbefore_exists: True\nafter_exists: False\n```\n\nExpected behavior:\n\nThe drive-relative member should be handled through the normal `tarfile` extraction-filter exception path, for example `OutsideDestinationError`, so that `errorlevel = 0` can skip/refuse that member and continue extracting later members.\n\nExpected output would be:\n\n```text\nbefore_exists: True\nafter_exists: True\n```\n\nI also observed the same raw `ValueError` behavior for drive-relative hardlink and symlink targets under `filter=\"data\"`.\n\nExpected structured exceptions:\n\n```text\nDrive-relative member name: OutsideDestinationError\nDrive-relative hardlink target: LinkOutsideDestinationError\nDrive-relative symlink target: LinkOutsideDestinationError\n```\n\nThe issue appears to come from `ntpath.commonpath()` raising `ValueError` for incompatible drive/path semantics, and that exception escaping directly instead of being converted into the appropriate `tarfile` filter exception.\n\nA possible fix would be to treat `ValueError` from the containment/commonpath check as an outside-destination condition and raise the appropriate structured `tarfile` exception.\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154993\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/zainnadeem786","@type":"Person","name":"zainnadeem786"},"datePublished":"2026-07-31T10:07:53Z","url":"https://github.com/python/cpython/issues/154987"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:5514c448-d415-f0eb-def6-5202ed3185c0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A20A:1201C:394CC9E:4C08628:6B0211FC |
| html-safe-nonce | eb18b58bab08c69f03f75f582d4908e5026dca5423c9095c695f53c388493fa5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjBBOjEyMDFDOjM5NENDOUU6NEMwODYyODo2QjAyMTFGQyIsInZpc2l0b3JfaWQiOiI4NDQ3NTc5MDQ1MjMwNjc4NTI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fc4e6ffe359f1f23093135e1334bf2a27b068f7d675454aa23f8546d21ad0551 |
| hovercard-subject-tag | issue:5028604588 |
| 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/154987/issue_layout |
| twitter:image | https://opengraph.githubassets.com/26c992f6164949c20a3db707d3c94a5c992a9a01cecbfe73194e6b63f70c220e/python/cpython/issues/154987 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/26c992f6164949c20a3db707d3c94a5c992a9a01cecbfe73194e6b63f70c220e/python/cpython/issues/154987 |
| og:image:alt | Bug report Bug description: tarfile extraction filters raise a raw ValueError on Windows when handling drive-relative member names or link targets such as C:bad.txt. This looks like an inconsistenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zainnadeem786 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width