Reject tar hard link targets that escape the extraction destination - #30878
Open
shaggyinsomniac wants to merge 1 commit into
Open
Reject tar hard link targets that escape the extraction destination#30878shaggyinsomniac wants to merge 1 commit into
shaggyinsomniac wants to merge 1 commit into
Conversation
shaggyinsomniac
force-pushed
the
fix/hardlink-escape-guard
branch
2 times, most recently
from
August 27, 2026 16:36
e2bd509 to
56e0cc7
Compare
Hard link targets are re-rooted at the extraction destination, so the existing relative-path guard never fires for them and a linkname like '../foo' can point outside the destination directory. Check the raw linkname for '..' segments before creating the link, similar to how GNU tar refuses such members by default.
shaggyinsomniac
force-pushed
the
fix/hardlink-escape-guard
branch
from
August 27, 2026 17:43
56e0cc7 to
4d4ce48
Compare
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.
Fixes #30875.
What
For hard links,
maybeDeprefixSymlinkis called withforceExtractRootRelative=true, which always returns an absolute fragment. That means the!targetName.isAbsolute()gate on the existing containment check can never fire for hard links, only for symlinks — so a tar member like a hard link to../fooslips past the guard and the link gets created outside the extraction destination.This PR checks the raw linkname (marker-stripped with
toRawBytesString) for..segments before creating the hard link, similar to how GNU tar refuses such members by default. Everything else in the extraction path is untouched.Testing
testDecompressTarWithHardlinkEscapenext to the existing symlink/regular-file escape tests: builds a tar.gz with a hard linklink->../fooand asserts decompression throws.//src/test/java/.../decompressor:DecompressorTestssuite passes locally (100/100).