Repository navigation
npm: bound a tarball's header blocks, and report npm's unpackedSize - #912
Merged
Merged
Conversation
The 512-byte header blocks did not count toward npm.max_unpacked_bytes, so a tarball of very many empty entries was bounded by the upload size alone. They now have the same bound again, counted apart from the entries' data: a package whose files fit the bound is read as before. dist.unpackedSize summed every entry, the data of PAX headers and GNU long names and entries of skipped types included. It is now what npm reports: the sizes of the entries node-tar hands npm (`npm pack <tarball> --json`, npm 10.9.9 with node-tar 7.5.22). Fixes #600 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJaP3vPrfBdtWXoxmth
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 17, 2026
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 #600
1. Header blocks count toward
npm.max_unpacked_bytesOnly the sizes the headers state counted, so a tarball of very many empty entries (512 bytes of header each, inflating about 1000:1) was bounded by the upload size alone.
Of the issue's two options I took counting the header blocks, not a cap on the number of entries: it needs no new setting and no number picked out of the air, and it bounds the thing that costs, the bytes inflated.
The blocks are counted apart from the data, against the same bound: a tarball is refused when its entries' data is over
max_unpacked, as before, or when its header blocks are. Adding both into one sum would newly refuse a package whose files add up to within512 × entriesof the limit; this way no tarball accepted for its data is refused unless its headers alone exceed the bound (over 2 million entries at the default 1 GiB). The archive now inflates to at most three times the bound (data, headers, and padding, which is less than a header per entry) instead of to whatever the upload holds.2.
dist.unpackedSizeis the size npm reportsIt summed every entry: PAX and GNU long-name data and entries of skipped types included.
What npm sums, as checked (npm 10.9.9, node-tar 7.5.22, pacote 19.0.2):
getContentsin npm'slib/utils/tar.jsaddsentry.sizefor every entrytar.t'sonentrygets. node-tar'sread-entry.jsmarks long names and PAX headers (L,K,N,x,X,g)metaand unknown typesignore;parse.jsemits neither.header.jsreads a directory's size as 0.npm pack <tarball> --json --dry-runon a crafted tarball holdingpackage.json(30), a file (100), a directory, a symlink, a hard link, a FIFO, a file under a GNU long name (7), a file under a PAX path (7), a contiguous file (5) and an entry of unknown typeZ(600 bytes) reportsunpackedSize: 149. Forge said 1082.This differs slightly from the issue's wording ("regular files only"): npm counts every entry node-tar emits, so a link or device whose header gives it a body is counted too. The same tarball plus a symlink stating 300 bytes of body gives
unpackedSize: 449in npm. No well-formed tarball has such an entry, so for those the two readings agree; I matched npm's measured value, and the regression test pins both numbers.What does not count in
unpackedSizestill counts toward the bound.file_countand the manifest choice are untouched. Versions already stored keep theunpackedSizethey were published with.Tests
Both written first and seen to fail on
main's reader:header_blocks_count_toward_the_unpacked_bound: empty entries (files, andL,x,K, directory headers) passing a 64 KiB bound are refused; a package whose files fill the bound and one with exactly as many entries as the bound holds blocks are still read; one byte more of data is refused as before.the_unpacked_size_is_the_one_npm_reports: the tarball above, 149 and 449.Ran:
cargo test -p forge-format-npm(64 + 15 pass),cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all --check,cargo xtask changelog --check.Notes
npm pack --json'sentryCountcounts directories, links and FIFOs (9 for the tarball above) where Forge'sdist.fileCountcounts files (5). Not part of this issue; raised separately.Generated by Claude Code