Repository navigation
fix(pack): support file paths longer than the tar name field - #36105
Merged
Merged
Conversation
`deno pack` failed with `error: provided value is too long when setting path for package/...` on any package containing a file whose packaged path reached 100 bytes. `append_reproducible` built each entry with `Header::set_path`, which copies straight into the 100-byte `name` field of a GNU header and errors out when the path doesn't fit. Use `Builder::append_data` instead: it routes through `prepare_header_path`, which transparently emits a GNU `././@LongLink` extension entry for long paths. This mirrors what `cli/tools/publish/tar.rs` already does for `deno publish`. Tarballs stay byte-reproducible — `append_data` sets the checksum itself, and the LongLink header the tar crate emits is fixed mode/uid/gid/mtime 0, so the existing `pack/reproducible` spec still passes. Fixes denoland#36008
The fixture's point is a packaged path that overflows the 100-byte GNU tar `name` field, but the on-disk path it checked into the repo was longer than it needed to be to prove that. Deno's CI runs on Windows, where MAX_PATH is 260 and there is no `core.longpaths` configuration in `.github/`, so an oversized fixture path is a needless checkout hazard. Use the filename from the issue instead. It keeps every on-disk component short (longest is 75 chars) and the tracked path at 135 chars, in line with existing repo norms, while the packaged paths still exceed the tar name field: package/kubernetes/models/_schemas/IoK8s...BindingList.js 110 bytes package/kubernetes/models/_schemas/IoK8s...BindingList.d.ts 112 bytes Verified the test still genuinely fails without the fix — reverting `append_reproducible` reproduces the issue denoland#36008 error verbatim: "provided value is too long when setting path for package/kubernetes/models/_schemas/". The extraction step now asserts the full extracted path via `find` rather than `ls` of the directory, so the output actually demonstrates the LongLink entry round-tripping. Comments in mod.ts and __test__.jsonc record that the length is the point, so the names don't get "tidied" shorter later.
Switching to `tar::Builder::append_data` to support paths longer than the 100-byte tar name field also removed the crate's `..` check for exactly those paths: `prepare_header_path`'s LongLink branch writes the full path with no component validation and only validates the truncated header name, which for a traversal path is all-normal segments. Short paths still error via `set_path`, so long and short disagreed. `to_tar_path` is the trigger: backslash is a legal POSIX filename character, so its unconditional replace turns one legal name into several segments, some of which can be `..`. Validate the normalized archive path before appending and return InvalidInput on any `..` or absolute path, so both lengths agree. Reject rather than sanitize, matching the pre-existing behavior for short paths. The fixed mode/mtime/uid/gid and the LongLink behavior are unchanged, so the tarball stays byte-reproducible.
bartlomieju
pushed a commit
that referenced
this pull request
Jul 23, 2026
Fixes #36008. `deno pack` failed on any package containing a file whose packaged path reaches 100 bytes — e.g. generated Kubernetes schema files: ``` error: provided value is too long when setting path for package/src/kubernetes/apimachinery/_schemas/ ``` ## Cause `append_reproducible` in `cli/tools/pack/npm_tarball.rs` assembled each tar entry by hand and called `tar::Header::set_path`. On a GNU header that copies straight into the fixed 100-byte `name` field and errors for anything longer. (The path in the error message looks truncated because the `tar` crate builds the message with `path_lossy()` over the partially-copied name field — it isn't the real offending path, so it's not worth chasing.) ## Fix Use `tar::Builder::append_data`, which transparently emits a GNU `././@LongLink` extension entry when the path doesn't fit, and computes the checksum. This is what `deno publish` already does (`cli/tools/publish/tar.rs`); `pack` was the odd one out. GNU LongLink is read by node-tar, so npm tooling handles the output. Reproducible tarballs are preserved: the `tar` crate emits the LongLink header with fixed mode/uid/gid and mtime 0, and the existing `pack/reproducible` spec still passes. ## Path validation `append_data` alone would trade the length bug for a narrow traversal gap, so this also adds explicit validation. When `prepare_header_path` falls back to LongLink, it writes the full path via raw `path2bytes` with no component validation and checks only the *truncated* header name (`copy_path_into_inner` permits `..` when `is_truncated_gnu_long_path` is set and it's the last component). So a path >= 100 bytes could smuggle `..` past the crate's checks while a short path was still rejected by `set_path`. That's reachable because a backslash is a legal character in a POSIX filename, and `to_tar_path` replaces backslashes unconditionally — so one legal filename can split into several archive segments. (Its doc comment previously claimed the opposite; corrected here.) `validate_tar_path` now runs on the normalized path before `append_data` and rejects `..`, absolute, and empty segments, so long and short paths behave identically. It splits the normalized `&str` on `/` rather than using `Path::components()`, whose parsing is platform-dependent on exactly these inputs. It rejects rather than sanitizes: silently rewriting would hide a malformed package. ## Tests - New spec test `tests/specs/pack/long_file_names/`, using the real filename from the issue (packaged: 110 bytes for the `.js`, 112 for the `.d.ts`). It packs, then extracts the tarball and asserts both full paths survive the round-trip. Reverting the fix makes this spec fail with the issue's exact error. - Unit tests in `npm_tarball.rs` covering the long-path round-trip, byte-for-byte determinism with a LongLink entry, and traversal rejection at both long (>100 byte) and short lengths. `cargo test -p deno --lib npm_tarball` and the full `pack::` spec family pass locally, as does a by-hand `deno pack` + `tar -tzf` on a package with a long path. --------- Co-authored-by: Nathan Whitaker <nathan@deno.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 #36008.
deno packfailed on any package containing a file whose packaged path reaches 100 bytes — e.g. generated Kubernetes schema files:Cause
append_reproducibleincli/tools/pack/npm_tarball.rsassembled each tar entry by hand and calledtar::Header::set_path. On a GNU header that copies straight into the fixed 100-bytenamefield and errors for anything longer.(The path in the error message looks truncated because the
tarcrate builds the message withpath_lossy()over the partially-copied name field — it isn't the real offending path, so it's not worth chasing.)Fix
Use
tar::Builder::append_data, which transparently emits a GNU././@LongLinkextension entry when the path doesn't fit, and computes the checksum. This is whatdeno publishalready does (cli/tools/publish/tar.rs);packwas the odd one out. GNU LongLink is read by node-tar, so npm tooling handles the output.Reproducible tarballs are preserved: the
tarcrate emits the LongLink header with fixed mode/uid/gid and mtime 0, and the existingpack/reproduciblespec still passes.Path validation
append_dataalone would trade the length bug for a narrow traversal gap, so this also adds explicit validation.When
prepare_header_pathfalls back to LongLink, it writes the full path via rawpath2byteswith no component validation and checks only the truncated header name (copy_path_into_innerpermits..whenis_truncated_gnu_long_pathis set and it's the last component). So a path >= 100 bytes could smuggle..past the crate's checks while a short path was still rejected byset_path.That's reachable because a backslash is a legal character in a POSIX filename, and
to_tar_pathreplaces backslashes unconditionally — so one legal filename can split into several archive segments. (Its doc comment previously claimed the opposite; corrected here.)validate_tar_pathnow runs on the normalized path beforeappend_dataand rejects.., absolute, and empty segments, so long and short paths behave identically. It splits the normalized&stron/rather than usingPath::components(), whose parsing is platform-dependent on exactly these inputs. It rejects rather than sanitizes: silently rewriting would hide a malformed package.Tests
tests/specs/pack/long_file_names/, using the real filename from the issue (packaged: 110 bytes for the.js, 112 for the.d.ts). It packs, then extracts the tarball and asserts both full paths survive the round-trip. Reverting the fix makes this spec fail with the issue's exact error.npm_tarball.rscovering the long-path round-trip, byte-for-byte determinism with a LongLink entry, and traversal rejection at both long (>100 byte) and short lengths.cargo test -p deno --lib npm_tarballand the fullpack::spec family pass locally, as does a by-handdeno pack+tar -tzfon a package with a long path.