Repository navigation
Conversation
…ion check pythongh-160097 moved data_filter's check for link members that resolve to the destination directory into the code shared with tar_filter, then made the shared check lexical (the member's normalised name is '.'). Link members reaching the destination any other way then passed even filter='data': * '../dest' raised RecursionError instead of OutsideDestinationError; * 's' -> '.' followed by a hard link 's/.' changed the destination directory's own mode; * '../current', where 'current' is an existing symlink outside the destination pointing at it, replaced that symlink and wrote later members outside the destination. Put the removed 'target_path == dest_path' check back in the 'data' link checks, keeping the lexical check that tar_filter gained. This restores data_filter's pre-pythongh-160097 behaviour exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019EeY1aVDfL7Y3eMxYWdYgc
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the minimal fix proposed in pythongh-160863, an alternative to the broader fix in #23.
python#160098 (for pythongh-160097) moved
data_filter's check for link members that resolve to the destination directory into the code shared withtar_filter. A later commit in that PR made the shared check lexical: it now looks only at whether the member's normalised name is.. As a result, link members that reach the destination any other way passfilter='data', which has been the default since 3.14:filter='data')maintoday../dest→destRecursionErrorOutsideDestinationErrord/,s→., hard links/.→dOutsideDestinationErrorfirst.txt,../current→real,later.txt, extracted into an existing symlinkcurrent→realcurrentis replaced andlater.txtis written outside the destinationOutsideDestinationErrorChange
Lib/tarfile.py: puts back the five lines that python#160098 removed from the'data'link checks (if target_path == dest_path: raise OutsideDestinationError, with their comment). The six-line lexical check thattar_filtergained is kept.data_filterbehaves exactly as it did before pythongh-160097.Lib/test/test_tarfile.py:test_link_resolving_to_destinationcovers the three reproducers from the issue underfilter='data'.No doc change: the
data_filterdocs did not describe this check before pythongh-160097 either.Compared with #23
This PR is smaller and only restores old behaviour, so it is the safer one to backport. It leaves two things as they were before pythongh-160097, and #23 fixes both:
tar_filterstill has only the lexical check, so../destands/.still passfilter='tar'. That is no regression:tar_filternever had this check beforetarfile.tar_filterdoesn't handle symlinks with empty names python/cpython#160097.filter='data': extracting an archive that containsself→.into the same directory a second time raisesOutsideDestinationError.Testing
Run on a Linux
--with-pydebugbuild:./python -m test test_tarfile test_shutil -u allpasses (1,032 run, 162 skipped).tarfile.pychange, the new test fails in all three cases: oneRecursionErrorand two "OutsideDestinationErrornot raised".Generated by Claude Code