Repository navigation
Hold a package to one set of size limits on every path, raise them, and make a limit an error (#2197) - #2410
Conversation
…it an error The tarball reader (npm tarballs, Python sdists) and the zip reader of the vendored-artifact checks (wheels, .nupkg) were sized for patch archives: 64 MiB unpacked, 10,000 entries, 16 MiB for one tarball member. They read whole packages now. A wheel with one compiled extension of 60 MiB, or an npm package of 31,858 files, could not be vendored or checked, and `vendor` said the service's archive "does not carry the patched files" (#2197). Both readers now take their limits from one place, `patch::archive_limits`: 200,000 entries, 512 MiB inflated in one read, and no more than 100 times the archive's own size once past the 64 MiB every archive may still use. The module docs give the packages the numbers were measured on. A member may be as large as what is left of its archive's budget; the tarball reader checks the declared size against that before it allocates. Both readers still hold what they inflate, so 512 MiB plus the archive is what reading one archive may take. Reaching a limit is now an error, never the end of the input (#2330). The tarball reader bounded the gzip stream with `Read::take`, which hands the tar parser an end of input at the limit. Between two entries the parser takes that for the end of the archive, so a second `package/index.js` placed exactly 64 MiB into the stream was never seen by the check for a second entry over a patched file, and the tarball verified. The stream is now read through a reader that fails on the first byte past the budget, and the walk reports that failure whatever the parser made of it. An archive past a limit says which limit, and what it holds or unpacks to where its own headers say: - `vendor --check`, `vex` and `repair` report a committed tarball, wheel, sdist or .nupkg as `vendor_artifact_too_large` (it was `vendor_artifact_unreadable`), and `vendor --check` names the limit. - `vendor` refuses a served Python distribution with `vendor_artifact_too_large`, and fails an npm package with "the patch service's tarball for <name>@<version> cannot be checked: <limit>". - `repair` reports a download past a limit the way it does for a jar. Three jar tests asserted that the wheel reader refuses a jar of 10,001 entries and 65 MiB; it reads one now, and the assertions are gone. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…r every archive `vex` words `vendor_artifact_too_large` for any vendored artifact now, not for a jar alone, and gives both sets of limits. Three tests in the vendor suite run the binary against the fixture patch service: - A package of 73 MiB in files of 14 MiB is vendored and checks clean. It failed with "does not carry the patched files". - A served tarball of some 80 KiB that unpacks to 80 MiB fails with a message that names the limit and what the tarball unpacks to, and nothing is committed. - A committed tarball with a second `package/index.js` exactly 64 MiB into its tar stream, its ledger fingerprint and lock integrity matching, fails `vendor --check` with `vendor_artifact_non_canonical`; it verified before (#2330). The same tarball without the second entry checks clean, and one past a limit fails with `vendor_artifact_too_large` and the limit named. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d wheels The CLI contract gains an "Archive limits" paragraph under the vendor command: the limits an npm tarball, a Python wheel or sdist and a .nupkg are read within, what each command reports for an archive past one, the packages the limits were measured on, and the two measured wheels that stay refused. The `vendor_artifact_too_large` row no longer says the tag is for jars only. The usage guide states the limits in its vendoring section. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… short The tarball extractor of `vendor::registry_fetch` (registry tarballs, crates, the data archive of a gem, the tarball of a vlt directory) bounded the gzip stream at 512 MiB with `Read::take`. A reader that stops at its limit hands the tar parser an end of input, and between two entries the parser takes that for the end of the archive: the files before the cap were written, the ones after it were not, and the extraction returned success. A package cut short was then judged by the files it did hold. The stream is now read through the reader that fails on the first byte past the cap, as the zip extractors beside it already count what they inflate: "tarball decompresses past the 536870912-byte cap". The caps themselves are unchanged. This is the third `take(limit)` site named in #2330; the other two are the tarball readers of `patch::package`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…read `vendor --check`, `vex` and `repair` refuse a committed npm tarball that holds a second entry an installer would extract over a patched file (`vendor_artifact_non_canonical`). The check ended a tarball where this crate's tar reader does, at the first all-zero block of the first gzip member. The installers read further, so a second `package/index.js` placed past that point verified here and installed the original (#2330). Measured with a tarball installed as a `file:` dependency: - npm 11.19.1 takes an entry that follows a single zero block (it ends an archive at two), passing over a block that is no tar header with a warning, and one in a second gzip member when the first has no end-of-archive marker. - Yarn 1.22.19 takes those, and an entry after the marker or in a second gzip member after it. The check now judges every entry up to the first zero block as before (an entry that cannot be read there still fails it), and then every entry after it: past zero blocks and blocks that are no header, to the end of the gzip member and through each member that follows. Nothing in that part fails the check for being unreadable, so a tarball with padding or other bytes after its marker verifies as it did. The limits count what is inflated there, and a limit that is met there is the same error. The reader that decodes the members for hashing is unchanged: it reads what it read, and the check above is what answers for the rest. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ge on disk too large
Three fixes from review of the archive limits.
A tarball member's buffer was reserved in one piece for the size its
header declares, once that size fit what is left of the archive's budget.
The budget is up to 512 MiB for an archive of five megabytes, where the
old cap on one member was 16 MiB, so a small crafted tarball could make
`vendor --check` or `vex` reserve half a gigabyte on a header's claim. On
a 32-bit build, or with overcommit off, that reservation fails and
`Vec::with_capacity` aborts the process. The buffer now starts at 128 KiB
and doubles as the content arrives, up to the declared size and never past
it, and a reservation the machine cannot make is the too-large error ("it
holds a member of 300 MiB, more than there is memory for"). The zip reader
reserves nothing on a declared size.
A committed wheel, sdist or npm tarball larger than 512 MiB on disk was
still `vendor_artifact_unreadable` ("cannot be read"): the size gate
before the readers returned that tag. It is `vendor_artifact_too_large`
now, as the contract says of an artifact past the limits, and
`vendor --check` says "it is 513 MiB on disk, over the 512 MiB a committed
artifact is read up to".
`vendor --check` named no limit when the limit was met only where the
check for a second entry reads, past the decoder's end of the tarball (a
second gzip member that inflates to 80 MiB): the text was recomputed with
the decoder, which never gets there. It is taken from the same walk now.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…aller reads alike The check for a second entry over a patched file (`vendor --check`, `vex`, `repair`: `vendor_artifact_non_canonical`) counted each entry under the name this crate's tar reader gives it. An entry's name can come from a header before it, a GNU long name or a PAX header, and the readers agree on it only while that header is in its usual shape. Away from it a tarball could hold the patched `package/index.js`, then an entry the check read as `package/harmless.js`, which an installer writes to `index.js`. Review found two such shapes; installing each with npm 11.19.1 and Yarn 1.22.19 found more. The second entry was installed over the patched file, and the check verified the tarball, when the header before it was: - a long name or PAX header without the ustar or GNU magic, which this crate's reader does not apply (npm, Yarn 1); - an old GNU long name, type `N` (npm, Yarn 1), or an old PAX header, type `X` (npm); - a PAX header with two `path` records, of which this crate's reader takes the first and the installers the last (npm, Yarn 1); - a PAX header with an empty line before its `path`, where this crate's reader stops (npm); - a PAX `path` followed by a long name (Yarn 1), or a global PAX header with a `path` followed by any PAX header (Yarn 1); - after the first zero block, a long name or PAX header and then a block that is no header: the walk restarted there and dropped the name, and npm keeps it (npm). The tar stream is now walked header by header, and a header that names another entry is taken in one shape only: it has the ustar or GNU magic and comes before the first zero block; a long name ends at its first NUL; a PAX header is `<length> <key>=<value>` lines and nothing else, each as long as it says, with one `path` at most and a `size` that is the entry's own; no entry has both; neither is larger than 64 KiB; a global PAX header holds a comment only. Any other shape counts as a second entry for a patched file, whichever file the entry after it would have been, since that depends on the installer. The usual shapes keep verifying: tarballs with long paths made by `npm pack`, bsdtar (pax and gnutar), Python's tarfile and `git archive` were run through the walk, as was a tarball vendored from the patch service. The decoder that reads the members for hashing is unchanged, and gives a canonical tarball's entries the same names. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview
Vendor/npm, PyPI, repair, reuse, registry tarball extraction, vex copy, and docs ( Reviewed by Cursor Bugbot for commit 1a8b66b. Configure here. |
This change is the size limits. Two commits on it also widened the check for a second entry over a patched file: one walked a tarball past its first zero block and its first gzip member, the next read the headers that name an entry in one shape only. That work is not ready (it refuses a tarball the patch service serves and `main` verifies) and moves to a change of its own. The remaining part of #2330 is tracked there. After this commit the check for a second entry, what `vendor --check`, `vex`, `repair`, the reuse of a committed tarball and a re-download take for a shadowing entry or a non-canonical tarball, and what the decoder reads into the member map are as on `main`, with one exception: a size or count limit that is met is an error that names the limit, where `main` read up to the limit and took the end of its input for the end of the archive. So the check ends at the first zero block of the first gzip member again, as the decoder does. What stays is the limits work: the shared limits and the reader that fails on the first byte past them, the limit errors and `vendor_artifact_too_large`, the registry extractor that fails where it extracted short, a member's buffer that grows as its content arrives (now in a form that compiles: it had landed inside the test module), and the too-large verdict for an artifact larger on disk than is read. Removed with the walks: their unit and CLI tests, the helpers on the bounded reader they alone used, and their wording in the `vex` omission and the check's message. The contract row for `vendor_artifact_non_canonical` is `main`'s text again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Each path that reads, unpacks or downloads a package had limits of its own, so one refused for its size what another took. They are one set now, defined in `patch::archive_limits` and named by the other modules: 200,000 entries, 1 GiB unpacked and at most 100 times the archive's own size past 64 MiB, 256 MiB downloaded, 512 MiB read of a committed file. What that raises: - The readers that hold an archive in memory (npm tarballs, wheels, source distributions, `.nupkg`): 512 MiB unpacked to 1 GiB, the jar reader's limit. `mkl` 2025.0.1 (521 MiB) and `tensorflow-cpu` 2.18.0 (946 MiB, 603 MiB of it one file) were refused and are read. - The registry extractors, which write to disk and hold a 64 KiB buffer: 60,000 entries to 200,000, 512 MiB unpacked to 1 GiB, and no limit on one entry below that (it was 128 MiB, which refused the 136 MiB file of `@next/swc-linux-x64-gnu`). A registry download: 128 MiB to 256 MiB, what a download from the patch service may be. - The inventory of a committed directory: 10,000 files to 200,000. A package past it was vendored with no inventory, which exact repair then refused (the wheel of `ansible` 11.1.0 holds 21,105 files). - A patched file recovered from a committed zip (`.nupkg`, wheel, jar): 64 MiB to what the readers let that zip unpack to, so still 64 MiB for a small one and a hundred times its size past that. A committed file that is read whole for it: 256 MiB to 512 MiB, and a file of a committed directory 64 MiB to 512 MiB. Nothing read before is refused now: no limit is lowered. A limit that is met is still an error that names the limit, and the ratio rule stands, so an archive must be 10.3 MiB itself to unpack to 1 GiB. A read holds what it unpacks once, beside the archive. With an npm tarball of 17 MiB that unpacks to 1,000 MiB, `vendor` peaked at 1,079 MiB resident, `vendor --check` at 1,055 MiB and `vex` at 1,059 MiB (macOS, aarch64, a debug build); with one that unpacks to 500 MiB, at 577, 552 and 557 MiB. Hashing members as they inflate would hold the archive alone, and is a change to every caller that takes the member map; it is not made here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…wanted Four things the review of the raised limits found. A patched file is recovered from a committed zip by reading its entries, and each read reserved a buffer of the size the entry declares. That size could be 64 MiB and can now be what the whole zip may unpack to: a committed wheel, `.nupkg` or jar of eleven megabytes whose entries each declare a gigabyte reserved a gigabyte for each, and where the machine refuses one (a commit limit, `ulimit -v`) `Vec::with_capacity` aborts the process. Nothing is reserved on the claim now; the buffer grows with what the entry inflates to, within the same cap. No other read the raise touched reserves on a size an archive or a response declares: the tarball reader grows a member's buffer already, and the others reserve a committed file's own size on disk, which the read then fills. Four callers read a whole tarball into memory for its `package.json`: the manifest of a hosted tarball, the name in a `file:` tarball of a Yarn lock, the manifest a vendored Yarn Berry entry is rendered from, and the one VEX discovery reads. Under the raised limit a tarball that unpacks to 800 MiB was held whole to read a name, where it stopped at 64 MiB before. They read the one member now, `read_archive_member`: the walk is the same, every entry counted and inflated within the same limits, so the same tarballs fail by the same errors, and the other members are passed over and not held. The reader that keyed every member under any top-level directory had no other caller and is gone; its rule is the one the one-member read applies. A limit error stated a multiple of the archive's own size with that size rounded up to a whole MiB: an archive of 1.2 MiB, held to 120 MiB, was "over 100 times its own size (2 MiB)". It is shown to a tenth of a MiB, rounded down. The `vex` omission for a too-large artifact still said 512 MiB for a tarball, wheel or `.nupkg`. Its numbers are the limits themselves now, and two comments that called the jar limit twice the in-memory one are corrected. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…l is read The tests of the registry extractors' caps built their fixtures at the caps themselves, which was affordable at 128 MiB an entry and 60,000 entries. At 1 GiB and 200,000 the test of the total cap allocated a gigabyte, deflated it and inflated it in three extractors (6.5 s and 1 GiB resident here), the test of the per-entry cap another gigabyte, and the test of the entry count built two archives of 200,001 entries. The total-cap test had also lost its case: with one entry allowed to be as large as the whole, it tripped on its second entry. The extractors take their caps as one value now, which a test can set for its own thread, and those tests run against 64 KiB an entry, 256 KiB in all and 40 entries: each in a hundredth of a second. They test the boundary again, exactly at a cap (taken) and one past it (refused), and their comments say what they do. Two tests of the raise itself are scaled down the same way: a tarball of 520 MiB read for real (590 MiB resident) is a tarball read against the limits at a 1024th, and the module zip of 60,001 entries and one of 129 MiB is an entry as large as the whole against small caps. The real values are asserted beside them. Two statements are corrected. The check for a second entry over a patched file was said to judge every entry up to the end-of-archive marker; it reads what the decoder reads, one gzip member up to the first all-zero block, and the doc comment and the contract say so, with #2330 for what lies behind. And the usage guide listed jars among the archives that are held in memory; a jar is hashed file by file. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
It sat above archive_limits_summary(), so the public function's rustdoc opened with the constant's sentence. Also join a jar comment in redownload.rs that was split across two blocks. Comments only. Assisted-by: Claude Code:claude-opus-5-5
Moving capped out of harvest_zip_blobs left harvest_zip_blobs' doc comment above capped. Comment-only move. Assisted-by: Claude Code:claude-opus-5-5
…-patch into fix/wheel-tgz-size-caps
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed the production diff at 8fbbf77: every package read path now takes its limits from archive_limits.rs, a hit limit returns an error instead of a short read, and the 100:1 ratio rule still bounds the in-memory readers. No defects found.
Non-blocking notes
harvest_artifact_blobs_from,read_package_json_from_vendored_tgzandpypi_uv::wheel_metadata_blockstill decode the whole archive to read one member, now up to 1 GiB.- The "run
socket-patch repair" remedy does not help an honest oversize artifact, as the description already flags.
Resolve the CLI_CONTRACT.md conflict in the verification-omission rows: keep this branch's archive-limit wording for vendor_artifact_too_large and main's new unreadable_file_mode reason in both rows. Assisted-by: Claude Code:claude-opus-5-5
Fixes #2197. Fixes the size-limit parts of #2330: the check that read short at its limit, and the false reason given for a package over it. The rest of #2330 is not in this PR (see "What it does not change").
The problem
Two readers decode a whole archive into memory: the tarball reader (npm tarballs, Python sdists) and the zip reader of the vendored-artifact checks (wheels,
.nupkg). Both were sized for patch archives of a few kilobytes: 64 MiB unpacked, 10,000 entries, 16 MiB for one tarball member. They read whole packages now, and released packages are larger, so a patch for one could not be vendored or checked, while a jar of the same size was accepted (200,000 entries, 1 GiB). Other paths had limits of their own: the registry extractors, the directory inventory, the harvest of patched files from a committed artifact. A package one path accepted could be refused by the next for size alone.Worse, the tarball reader stopped at its limit with
Read::take. The tar parser takes an end of input between two entries for the end of the archive, so every entry past 64 MiB was never seen and no error was raised (#2330).vendor --checkandvexthen verified a tarball whose secondpackage/index.js, the one an installer extracts last, sat past the limit.What changes
One set of limits, in one place (
patch/archive_limits.rs), raised so that the packages measured below pass on every path:main.nupkg)Nothing is lowered, and nothing that was read before is refused now.
Measured packages (wheels from their zip directories, tarballs streamed, nothing extracted):
mainnext15.1.0@mui/icons-material6.2.1@next/swc-linux-x64-gnu15.1.0onnxruntime-node1.20.1ansible11.1.0 (wheel)xgboost2.1.3 (wheel)paddlepaddle2.6.2 (wheel)mkl2025.0.1 (wheel)tensorflow-cpu2.18.0 (wheel)All nine are within the new limits. The last two are so by their measured sizes; the wheels themselves were not run through the readers.
What the 1 GiB costs. These readers hold what they inflate. A synthetic npm tarball of 17 MiB that unpacks to 1,000 MiB, served by a local stand-in for the patch service (macOS, aarch64, debug build):
vendorvendor --checkvexSo a read costs what it unpacks, plus the archive, plus about 60 MiB. The worst case by arithmetic is about 1.3 GiB for a 256 MiB download and 1.6 GiB for a 512 MiB committed file. A crafted archive must itself be 10.3 MiB to reach 1 GiB, because the ratio rule stands.
A limit is an error. A new
Boundedreader fails on the first byte past the budget, in the two tarball readers and in the registry extractor (which used to write a tree short of the files past its cap and return success). A member's buffer starts at 128 KiB and grows as content arrives, so a header's claim reserves nothing, and a reservation the machine cannot make is the too-large error, not an abort. The error names the limit and what the archive holds:it unpacks to 1100 MiB, over the limit of 1024 MiB for one archive,it holds 200001 entries, over the limit of 200000. A committed archive over a limit isvendor_artifact_too_large(it wasvendor_artifact_unreadable, or verified), on disk as well as unpacked.Checked against
mainon real tarballsThe check for a second entry over a patched file, and what the readers accept, are meant to be exactly
main's apart from the limits. Compared with a binary built frommain:next12.0.0,webpack5.0.0,lodash4.17.20,ejs3.1.6), committed in one project:vendor --checkverifies 35 with both binaries andvexwrites the same 42 statements.scan --mode vendoredof that project with each binary: the same 105 events, and the 35 vendored tarballs are byte-identical. A second run and arepairafter deleting two tarballs give the same events too.mainat9f2bc04(81 from the registry, 8 written bynpm pack, bsdtar, Pythontarfileandgit archive, 36 from the patch service, 83 crafted, 2 large fixtures), comparing member maps by name and SHA-256 and the shadowing verdict: 200 identical, 10 differ, and all 10 are archivesmaincannot read past its limits (@mui/icons-material,aws-sdk,googleapis,monaco-editor,next, three crafted limit shapes and the two large fixtures).That comparison is why this PR is smaller than its first pushes. Two earlier commits made the second-entry check read on past the end-of-archive marker and take long-name and PAX headers into account, and a stricter version of it refused the service's
ejs3.1.6 tarball, whose top directory isejs-v3.1.6/and notpackage/. That work is taken out again (commit55b009a) and kept on the branchfix/npm-tarball-canonical-shapefor #2330. The comparison also found #2423, which is onmaintoo:repaircannot restore thatejstarball.What it does not change
vendor --checkandvex, as onmain.applyandget: they do not use these readers since v5 removed the diff-archive path.RECORDat 16 MiB,METADATA, gemspecs, POMs, lock and build files), theshowdisplay cap, the crawlers' directory budgets.For the maintainers to decide
socket-patch repair" is wrong for an honest oversize artifact: the re-download is refused the same way. Jars have the same wording today.apply_failed; only the detail names the limit.ArchiveError::EntryTooLargeandTooManyEntriesvariants are replaced byTooLarge(String). Nothing in the workspace used them.Review
/code-review highran twice on earlier versions of this PR.main. That work is no longer in this PR, and the check here ismain's (see the comparison above).The third pass, on this limits-only version, found nine things. Seven are fixed, in the last two commits; those two commits were not put through another review pass (I read the new one-member reader, and the comparison with
mainabove was repeated on them):vexomission text still said 512 MiB.docs/usage.mdsaid a jar's contents are held in memory.package.json(VEX discovery, the hosted manifest read, two Yarn readers) held the whole package, which after the raise could be 1 GiB. They read that one member now, through the same walk and within the same limits.Two are left:
main's behaviour and the open part of vendor --check and vex stop reading a vendored npm tarball before the installers do, and a package over 64 MiB is refused for a false reason #2330.Tests
tests/vendor/vendor_failure_paths.rs): a 73 MiB package is vendored and checked; a served tarball past what its size allows is refused as too large;vendor --checksees a second entry where the old limit fell.cargo fmt --check,cargo clippy --workspace --all-features -- -D warnings,cargo check --workspace --all-targets --all-features, core lib (8,799 passed), CLI lib (1,086),vendor(149),repair(118),vex(29),e2e_vex_vendor(39),in_process_vendor(157), and 22 further CLI binaries (623 passed).0eab05dthrough the Windows-only CI dispatch (run 46762610782). All 24 jobs passed, and again on8fbbf77aftermainwas merged in (run 46797447199).Commit
633811024does not compile on its own (a hunk landed at the wrong lines; the next commit holds the correct file). The branch head is what was built and tested.🤖 Generated with Claude Code
Generated by Claude Code