Repository navigation
Conversation
`strip_prefix` is handed to tar as a member pattern, which is positional. bsdtar -- macOS `tar` and Windows `tar.exe` -- stops parsing options at the first positional, so the `--exclude-from=` that `unarchive.bzl` appended after it was read as a second member pattern rather than a flag. GNU tar tolerates these being in either order so nobody noticed. Split the strip-prefix handling into the `--strip-components=N` flag and the member pattern, and emit the member pattern at the very end of the command line. The regression test packs a fixture tarball with a genrule and extracts it with both attributes set, then verifies the files exist when extracted. The test in question is totally vibed but my claude claims it tried running it. Concretely: create the tar from the test here, then: gnu tar: $ tar xf foo.tar.gz wrapper/nested --strip-components=1 (success) bsd tar: $ tar xf foo.tar.gz wrapper/nested --strip-components=1 tar: --strip-components=1: Not found in archive tar: Error exit delayed from previous errors. Assisted-By: Claude Opus 5
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D120789614. (Because this pull request was imported automatically, there will not be any future comments.) |
meta-codesync Bot
pushed a commit
that referenced
this pull request
Nov 28, 2026
Summary: `excludes` of `http_archive` and `extract_archive` matches its regexes against `tar --list`, then writes the matched member names to a file that tar reads with `--exclude-from`. tar reads each line of that file as a glob pattern, not as a name. A member whose name contains `[`, `*` or `?` is not excluded, and other members that the pattern happens to match are dropped instead. tar exits 0, so the build succeeds with the wrong set of files. Names like that are common in web projects: Next.js, SvelteKit and Astro name route files `[id].js` or `[...slug].tsx`. This PR escapes `\`, `*`, `?` and `[` in each name it writes to the list. GNU tar and bsdtar both read an escaped character literally. ## Affected version origin/main 00c2ee4. The exclusion list has been written this way since 8af857a ("http_archive: reimplement exclusion lists using dynamic_output"). ## Reproduction ``` mkdir -p pages && for f in '[id].js' d.js index.js; do echo x > "pages/$f"; done tar -czf archive.tar.gz pages ``` ```python extract_archive( name = "extracted", src = "archive.tar.gz", excludes = ["^pages/\\[id\\]\\.js$"], ) ``` `buck2 build :extracted --show-full-simple-output`, then list the output directory. ## Expected `pages/d.js` and `pages/index.js`. ## Actual `pages/[id].js` and `pages/index.js`. The exclusion list holds `pages/[id].js`, and tar reads `[id]` as the character class "i or d". Same result with GNU tar 1.35 (Debian) and bsdtar 3.5.3 (macOS). Pull Request resolved: #1666 Test Plan: - New `tests/prelude/http_archive/excludes_with_glob_characters`: archives `pages/{[id].js,d.js,index.js}`, extracts with the exclude above, and asserts the result is exactly `pages/d.js` and `pages/index.js`. - Checked with a locally built buck2 on macOS. origin/main extracts `[id].js` and `index.js`; this branch extracts `d.js` and `index.js`. A plain exclude (`"index"`) gives the same result as before. - GNU tar 1.35 with the escaped list extracts exactly `d.js` and `index.js`. This touches the same file as #1512 (`excludes` with `strip_prefix` on bsdtar) but different lines, and fixes a separate problem. Reviewed By: dtolnay Differential Revision: D134821702 fbshipit-source-id: 18c7d4ea2335fec790a18a7f1f43ff4d24762b82
This branch has not been deployed
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.
strip_prefixis handed to tar as a member pattern, which is positional.bsdtar -- macOS
tarand Windowstar.exe-- stops parsing options at thefirst positional, so the
--exclude-from=thatunarchive.bzlappended afterit was read as a second member pattern rather than a flag. GNU tar
tolerates these being in either order so nobody noticed.
Split the strip-prefix handling into the
--strip-components=Nflag and themember pattern, and emit the member pattern at the very end of the
command line.
The regression test packs a fixture tarball with a genrule and extracts it with
both attributes set, then verifies the files exist when extracted.
The test in question is totally vibed but my claude claims it tried
running it.
Concretely: create the tar from the test here, then:
gnu tar:
$ tar xf foo.tar.gz wrapper/nested --strip-components=1
(success)
bsd tar:
$ tar xf foo.tar.gz wrapper/nested --strip-components=1
tar: --strip-components=1: Not found in archive
tar: Error exit delayed from previous errors.
Assisted-By: Claude Opus 5