Skip to content

Hold a package to one set of size limits on every path, raise them, and make a limit an error (#2197) - #2410

Merged
Mikola Lysenko (mikolalysenko) merged 17 commits into
mainfrom
fix/wheel-tgz-size-caps
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 17 commits into
mainfrom
fix/wheel-tgz-size-caps

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

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 --check and vex then verified a tarball whose second package/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:

Limit main This PR Bounds
Unpacked size, in-memory readers (npm tarball, wheel, sdist, .nupkg) 64 MiB 1 GiB, and at most 100 times the archive's own size once past 64 MiB memory
Entries, in-memory readers 10,000 200,000 count
One tarball member 16 MiB no separate limit: what is left of its archive's allowance memory
Unpacked size, registry extractors 512 MiB 1 GiB disk
One entry, registry extractors 128 MiB no separate limit disk
Entries, registry extractors 60,000 200,000 count
Registry download, Maven artifacts included 128 MiB 256 MiB memory
Directory inventory 10,000 files 200,000 memory (about 30 MiB of map; files are hashed streaming)
Patched file harvested from a committed zip 64 MiB what that zip may unpack to memory, one member at a time
Committed file read for the harvest 256 MiB 512 MiB memory
One file of a committed directory, harvest 64 MiB 512 MiB memory
Jar reader 200,000 entries, 1 GiB, 100:1 unchanged, now the shared constants streaming
Download from the patch service 256 MiB unchanged memory
Committed artifact read whole 512 MiB unchanged memory

Nothing is lowered, and nothing that was read before is refused now.

Measured packages (wheels from their zip directories, tarballs streamed, nothing extracted):

Package Archive Unpacked Entries Largest member main
next 15.1.0 24.1 MiB 115.0 MiB 6,873 10.2 MiB refused
@mui/icons-material 6.2.1 1.6 MiB 17.2 MiB 31,858 2.2 MiB refused
@next/swc-linux-x64-gnu 15.1.0 44.2 MiB 135.7 MiB 3 135.7 MiB refused
onnxruntime-node 1.20.1 66.8 MiB 180.1 MiB 36 27.3 MiB refused
ansible 11.1.0 (wheel) 49.0 MiB 185.1 MiB 21,105 2.7 MiB refused
xgboost 2.1.3 (wheel) 146.8 MiB 239.3 MiB 47 238.5 MiB refused
paddlepaddle 2.6.2 (wheel) 120.1 MiB 430.0 MiB 2,478 219.4 MiB refused
mkl 2025.0.1 (wheel) 176.2 MiB 521.1 MiB 39 66.6 MiB refused
tensorflow-cpu 2.18.0 (wheel) 219.6 MiB 945.6 MiB 12,487 603.3 MiB refused

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):

Unpacks to vendor vendor --check vex
1,000 MiB 1,079 MiB resident 1,055 MiB 1,059 MiB
500 MiB 577 MiB 552 MiB 557 MiB

So 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 Bounded reader 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 is vendor_artifact_too_large (it was vendor_artifact_unreadable, or verified), on disk as well as unpacked.

Checked against main on real tarballs

The 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 from main:

  • 35 patched npm tarballs from the patch service (among them next 12.0.0, webpack 5.0.0, lodash 4.17.20, ejs 3.1.6), committed in one project: vendor --check verifies 35 with both binaries and vex writes the same 42 statements.
  • A fresh scan --mode vendored of that project with each binary: the same 105 events, and the 35 vendored tarballs are byte-identical. A second run and a repair after deleting two tarballs give the same events too.
  • 210 tarballs through the reader functions, repeated at the head against main at 9f2bc04 (81 from the registry, 8 written by npm pack, bsdtar, Python tarfile and git 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 archives main cannot 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 ejs 3.1.6 tarball, whose top directory is ejs-v3.1.6/ and not package/. That work is taken out again (commit 55b009a) and kept on the branch fix/npm-tarball-canonical-shape for #2330. The comparison also found #2423, which is on main too: repair cannot restore that ejs tarball.

What it does not change

  • The rest 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. A second entry after the end-of-archive marker or in a second gzip member is still not seen by vendor --check and vex, as on main.
  • Agent-mode apply and get: they do not use these readers since v5 removed the diff-archive path.
  • The registry extractors have no ratio rule, as before, so a small crafted registry archive can now write 1 GiB to disk where it could write 512 MiB.
  • The harvest of patched files still skips a member over its limit without an error, as before.
  • Limits on things that are not package content are untouched: self-update downloads, metadata reads (a wheel's RECORD at 16 MiB, METADATA, gemspecs, POMs, lock and build files), the show display cap, the crawlers' directory budgets.

For the maintainers to decide

  1. The values. 1 GiB unpacked, 200,000 entries, 256 MiB registry download. A package between 512 MiB and 1 GiB is read where a first version of this PR refused it by name; on a CI container with less memory than the table above, that read can now be killed by the system instead. Reading only the members a check needs (streaming) would remove that; every caller takes the whole member map today, so it is not a contained change.
  2. No per-member limit.
  3. The remedy text. "Run socket-patch repair" is wrong for an honest oversize artifact: the re-download is refused the same way. Jars have the same wording today.
  4. npm vendoring failures still carry apply_failed; only the detail names the limit.
  5. The public ArchiveError::EntryTooLarge and TooManyEntries variants are replaced by TooLarge(String). Nothing in the workspace used them.

Review

/code-review high ran twice on earlier versions of this PR.

  • The first pass found five things. Two were about limits and are fixed here: a member's buffer was reserved on its header's claim (up to the whole allowance for a small crafted tarball), and an artifact over 512 MiB on disk was still "cannot be read". The other three were about the second-entry check.
  • The second pass found six, all in the second-entry check work, one of them a regression against main. That work is no longer in this PR, and the check here is main'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 main above was repeated on them):

  • Important: the harvest of patched files from a committed zip reserved memory on the size the zip's own header declares, which after the raise could be 1 GiB for each entry of a small crafted archive. It reserves nothing now and grows as content arrives.
  • Three tests scaled with the raised constants (one allocated 1 GiB and deflated 4 GiB of zeros). They run against small test-only limits now, the at-the-limit case is back, and the real constants are asserted beside them.
  • The vex omission text still said 512 MiB.
  • The ratio error rounded the archive's own size up, so "over 100 times its own size (2 MiB)" could be printed for an archive of 1.2 MiB.
  • docs/usage.md said a jar's contents are held in memory.
  • Callers that want only a tarball's 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.
  • A doc comment claimed the check judges every entry up to the end-of-archive marker. It now says what the reader does: one gzip member, up to the first all-zero block.

Two are left:

Tests

  • Unit: a limit is an error at every byte offset; a second entry past the old 64 MiB mark is seen; a bomb is refused quickly and costs the budget, not its own size; a 1 GiB header claim is refused before allocation; a zip entry's declared size reserves nothing; one member is read without the others, with the same errors as the full read; an entry may be as large as its package; a directory of more files than the old inventory limit records its inventory (cargo, Go, Composer); a member past the old 64 MiB harvest limit yields its patched blob. The limit tests of the registry extractors and of the 1 GiB ceiling run against small injected limits, so no test reads a tarball of 520 MiB for real; the measurements above did.
  • CLI (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 --check sees a second entry where the old limit fell.
  • Not tested directly: a registry download between 128 and 256 MiB, and the two 512 MiB harvest limits. The inventory's named error is shown at a small limit plus an assertion on the constant.
  • Run locally at the head: 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).
  • Windows: PR CI has no Windows job, so the workspace test job and the Windows end-to-end jobs were run on the head commit 0eab05d through the Windows-only CI dispatch (run 46762610782). All 24 jobs passed, and again on 8fbbf77 after main was merged in (run 46797447199).

Commit 633811024 does 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

…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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 16:57
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes core tarball/zip decoding, memory budgeting, and verification semantics for vendored artifacts; incorrect limit or shadow-entry logic could refuse valid packages or miss malicious tarballs, but scope is bounded to vendor/check paths with extensive new tests.

Overview
Raises archive read limits for npm tarballs, Python wheels/sdists, and .nupkg from the old patch-sized caps (64 MiB / 10k entries / 16 MiB per member) to a shared policy: 200k entries, 512 MiB inflated, and 100× archive size past a 64 MiB floor, via new patch::archive_limits and a Bounded reader that errors on overrun instead of silently truncating like Read::take—so large honest packages (e.g. ~73 MiB npm) can vendor/check, and oversize archives surface vendor_artifact_too_large with explicit limit detail rather than false “missing patch” failures.

shadowed_member / vendor_artifact_non_canonical now scans tar streams the way npm 11 and Yarn 1 do: past the first zero block, junk blocks, and additional gzip members; second entries named via GNU long names or PAX path are detected only when headers match the “usual” shape installers agree on.

Vendor/npm, PyPI, repair, reuse, registry tarball extraction, vex copy, and docs (CLI_CONTRACT.md, usage.md) are updated so limit breaches are classified and messaged consistently end-to-end.

Reviewed by Cursor Bugbot for commit 1a8b66b. Configure here.

@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as draft December 1, 2026 17:26
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>
@mikolalysenko Mikola Lysenko (mikolalysenko) changed the title Raise the tarball and wheel size limits, and make a limit an error instead of an end of archive (#2197) Hold a package to one set of size limits on every path, raise them, and make a limit an error (#2197) Dec 1, 2026
Main has moved since this branch was cut (thirteen commits, #2409 and
#2392 among them). The merge is clean: the two files both sides changed,
vendor/mod.rs and vendor/verify.rs, merged without a conflict.

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>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 1, 2026 22:43
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 1, 2026
Claude (claude) and others added 4 commits December 2, 2026 01:19
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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_tgz and pypi_uv::wheel_metadata_block still 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
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 545ea83 Dec 2, 2026
118 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/wheel-tgz-size-caps branch December 2, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

3 participants