Title: `TarFile.extractall` seeks backwards · Issue #106980 · python/cpython · GitHub
Open Graph Title: `TarFile.extractall` seeks backwards · Issue #106980 · python/cpython
X Title: `TarFile.extractall` seeks backwards · Issue #106980 · python/cpython
Description: Bug report Using tarfile.TarFile.extractall on a compressed tarball opened in a streaming mode, like r|bz2, results in a tarfile.StreamError: Traceback (most recent call last): File "C:\
Open Graph Description: Bug report Using tarfile.TarFile.extractall on a compressed tarball opened in a streaming mode, like r|bz2, results in a tarfile.StreamError: Traceback (most recent call last): File "C:\
X Description: Bug report Using tarfile.TarFile.extractall on a compressed tarball opened in a streaming mode, like r|bz2, results in a tarfile.StreamError: Traceback (most recent call last): File "C:\<re...
Opengraph URL: https://github.com/python/cpython/issues/106980
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`TarFile.extractall` seeks backwards","articleBody":"# Bug report\r\n\r\nUsing `tarfile.TarFile.extractall` on a compressed tarball opened in a streaming mode, like `r|bz2`, results in a `tarfile.StreamError`:\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"C:\\\u003credacted>\\git.py\", line 22, in install\r\n tar.extractall(_PATH_TO_GIT_FOR_WINDOWS)\r\n File \"tarfile.py\", line 2257, in extractall\r\n File \"tarfile.py\", line 2320, in _extract_one\r\n File \"tarfile.py\", line 2403, in _extract_member\r\n File \"tarfile.py\", line 2446, in makefile\r\n File \"tarfile.py\", line 520, in seek\r\ntarfile.StreamError: seeking backwards is not allowed\r\n```\r\n\r\nI would expect this to work as the seeks should only ever move forward past headers and never backwards: read a header, create the file/directory, and repeat.\r\n\r\n## Background\r\n\r\nI have a little script that shims calls to `git`. If it can't find `git` in the path, it downloads a portal version of Git for Windows and uses that. Conveniently, Git for Windows distributes bzip2 compressed tarballs, which can be decompressed and extracted with a few short lines. However, doing so in streaming mode (`r|bz2`) results in a `tarfile.StreamError`.\r\n\r\n## Repro\r\n\r\nHere's a minimal script that reproduces the error.\r\n\r\n```py\r\nimport urllib.request\r\nimport tarfile\r\n\r\nurl = \"https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.1/Git-2.41.0-64-bit.tar.bz2\"\r\n\r\nwith urllib.request.urlopen(url) as response:\r\n with tarfile.open(fileobj=response, mode='r|bz2') as tar:\r\n tar.extractall(\"git-for-windows\")\r\n```\r\n\r\nAs a workaround, I currently download the tarball to a temporary file and extract from there.\r\n\r\n# Your environment\r\n\r\nI'm running into this on Windows 10, Version 10.0.19045 Build 19045, using a portable installation of Python.\r\n\r\n```\r\nPython 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32\r\n```","author":{"url":"https://github.com/mtwilliams","@type":"Person","name":"mtwilliams"},"datePublished":"2023-07-21T22:52:27Z","url":"https://github.com/python/cpython/issues/106980"}
| 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:ff4fed33-9a92-a1d7-48bc-c8790dd5f86d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA32:97D39:D2D9EB:1167295:6B01FCF5 |
| html-safe-nonce | b71ef2a7d8f48f6bc95683317c4a4a3c070d5e69f981ae701af91acaf3e87aac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTMyOjk3RDM5OkQyRDlFQjoxMTY3Mjk1OjZCMDFGQ0Y1IiwidmlzaXRvcl9pZCI6IjQzOTA1MzYxMzQ0OTQ3NzM2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2f25313d790f8e0fbf0e66ee5950f01cb50d82a0063804aa6a0623faa0584e2e |
| hovercard-subject-tag | issue:1816458453 |
| 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/106980/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3df759ff0c06ce4ac704c5295d647bff4ec942e5590a1d1594534db9f381afd6/python/cpython/issues/106980 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3df759ff0c06ce4ac704c5295d647bff4ec942e5590a1d1594534db9f381afd6/python/cpython/issues/106980 |
| og:image:alt | Bug report Using tarfile.TarFile.extractall on a compressed tarball opened in a streaming mode, like r|bz2, results in a tarfile.StreamError: Traceback (most recent call last): File "C:\ |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mtwilliams |
| 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