Repository navigation
unpack: do not mutate cwd when extract strip empties a path - #465
Closed
dyk1454683243-sudo wants to merge 2 commits into
Closed
dyk1454683243-sudo wants to merge 2 commits into
dyk1454683243-sudo wants to merge 2 commits into
Conversation
GNU tar --strip-components skips members whose names become empty. node-tar applied those directory entries to cwd, so extract with strip as root could change ownership, mode, and mtime of existing directories. Fixes isaacs#294. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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 #294
Problem
extract({ strip })treated a fully-stripped directory entry as the extraction directory. As root (or withpreserveOwner/chmod), that applied the archive member's uid/gid, mode, and mtime to an existing cwd.GNU tar
--strip-componentsskips members whose names become empty. It does not chown or chmod.in the reporter's reproduction:node-tar's equivalent
tar.x({ file, strip: 1 })changed cwd ownership to 501.This matches the existing contract in
TarOptions.strip("any entry whose entire path is stripped will be excluded"), butdiranddir/still resolved to cwd afterparts.splice.Fix
After applying
strip, skip the entry when only empty /.segments remain. Remaining names (pkg/sub→sub) are still extracted, including metadata on existing remaining directories, which is what GNU tar-p --strip-componentsdoes.Tests
test/unpack.js(strip does not mutate existing cwd (#294)):preserveOwnerdoes notchowncwddir/(cwd unchanged)./keepmeafterstrip: 1still extractsstrip: 2ona/b/does not mutate cwdpre/.afterstrip: 1does not mutate cwdDiscriminating check: the new tests fail on
2a22bfc(17 assertion failures) and pass on this branch.Test plan
npx tap test/unpack.js --disable-coverage -t0: 692/692 passCHECKPATHskip and pass with it