FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-112887: Fix tarfile FilterError handling to skip member extraction by mattprodani · Pull Request #112954 · python/cpython · GitHub

/ cpython Public

gh-112887: Fix tarfile FilterError handling to skip member extraction - #112954

Closed
mattprodani wants to merge 3 commits into
python:mainfrom
mattprodani:safetar
Closed

gh-112887: Fix tarfile FilterError handling to skip member extraction#112954
mattprodani wants to merge 3 commits into
python:mainfrom
mattprodani:safetar

Conversation

mattprodani commented Dec 11, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

In tarfile library, if a FilterError is raised for a member during TarFile.extract() or TarFile.extractall() with errorlevel set to 0, a debugging message is correctly logged but the unsafe member is still extracted. Based on the documentation and a look at the code, it seems that the desired expectation with errorlevel=0 is to not raise an exception, but skip member extraction and log the error.
Updates tarfile to properly handle FilterError and skip extraction on unsafe members even when an exception is not raised.

This issue was reported on Python 3.11 and should likely be backported as it is a security issue.

From the docs:

When a filter refuses to extract a file, it will raise an appropriate exception, a subclass of FilterError. This will abort the extraction if TarFile.errorlevel is 1 or more. With errorlevel=0 the error will be logged and the member will be skipped, but extraction will continue.

In `tarfile` library, FilterError with error_level set to 0 correctly logged a debugging
message but did not properly skip extraction of a member. Updates filter
functions to return None when a FilterError is seen, as stated in docs.
mattprodani changed the title gh-112887: Fix tarfile FilterError handling to skip member extraction gh-112887: [WIP] Fix tarfile FilterError handling to skip member extraction Dec 11, 2023
mattprodani changed the title gh-112887: [WIP] Fix tarfile FilterError handling to skip member extraction gh-112887: Fix tarfile FilterError handling to skip member extraction Dec 12, 2023
mattprodani marked this pull request as ready for review December 12, 2023 20:37

encukou commented Jun 4, 2025

Copy link
Copy Markdown
Member

Thank you for the fix. I included it, in a “Ship of Theseus” style, in #135037 which fixes a few other security issues as well.

I forgot to include you in the Git authorship metadata. I apologize for that. You're credited in What's New though: https://docs.python.org/3.14/whatsnew/3.14.html#tarfile

encukou closed this Jun 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL