Skip to content

Reject tar hard link targets that escape the extraction destination - #30878

Open
shaggyinsomniac wants to merge 1 commit into
bazelbuild:masterfrom
shaggyinsomniac:fix/hardlink-escape-guard
Open

Reject tar hard link targets that escape the extraction destination#30878
shaggyinsomniac wants to merge 1 commit into
bazelbuild:masterfrom
shaggyinsomniac:fix/hardlink-escape-guard

Conversation

@shaggyinsomniac

@shaggyinsomniac shaggyinsomniac commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #30875.

What

For hard links, maybeDeprefixSymlink is called with forceExtractRootRelative=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 ../foo slips 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

  • New testDecompressTarWithHardlinkEscape next to the existing symlink/regular-file escape tests: builds a tar.gz with a hard link link -> ../foo and asserts decompression throws.
  • Full //src/test/java/.../decompressor:DecompressorTests suite passes locally (100/100).

@github-actions github-actions Bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Aug 26, 2026
@shaggyinsomniac
shaggyinsomniac force-pushed the fix/hardlink-escape-guard branch 2 times, most recently from e2bd509 to 56e0cc7 Compare August 27, 2026 16:36
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
shaggyinsomniac force-pushed the fix/hardlink-escape-guard branch from 56e0cc7 to 4d4ce48 Compare August 27, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompressedTarFunction: tar hard-link linknames with '..' escape the extraction destination (guard never fires for hard links)

1 participant