Skip to content

fix(pack): support file paths longer than the tar name field - #36105

Merged
nathanwhit merged 3 commits into
denoland:mainfrom
nathanwhitbot:orcha/impl-32b12fd1
Jul 17, 2026
Merged

nathanwhit merged 3 commits into
denoland:mainfrom
nathanwhitbot:orcha/impl-32b12fd1

Conversation

@nathanwhitbot

Copy link
Copy Markdown
Contributor

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.

`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.
@nathanwhit
nathanwhit merged commit c71e43a into denoland:main Jul 17, 2026
136 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long package file names trigger "Provided value is too long when setting path" in deno pack

2 participants