Skip to content

Raise the tarball and wheel size limits, and make a limit an error instead of an end of archive (#2197) - #2410

Draft
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
fix/wheel-tgz-size-caps
Draft

Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
mainfrom
fix/wheel-tgz-size-caps

Conversation

@mikolalysenko

Copy link
Copy Markdown
Collaborator

Fixes #2197. Fixes the read-short parts of #2330.

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

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 for both readers (patch/archive_limits.rs): 200,000 entries, 512 MiB inflated, and no more than 100 times the archive's own size once past 64 MiB. Nothing that was read whole before is refused now. There is no separate limit on one member: a member may be as large as what is left of its archive's budget, checked against its declared size before anything is allocated.

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

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

The last two stay refused. 512 MiB and not the jar reader's 1 GiB because these readers hold what they inflate, while the jar reader holds a digest per member.

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). The error names the limit and what the archive holds: it unpacks to 946 MiB, over the limit of 512 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).

The check for a second entry over a patched file reads as far as the installers do (last commit, separable). Probed with npm 11.19.1 and Yarn 1.22.19 on tarballs installed as file: dependencies:

Second package/index.js placed npm installs Yarn 1 installs
after one zero block the second the second
after one zero block and a non-header block the second (warns TAR_ENTRY_INVALID) fails
in a second gzip member, the first without an end marker the second the second
after the two-block end marker the first the second
in a second gzip member, after the end marker the first the second

Before this change vendor --check and vex verified all five. The first three reach npm itself, which #2330 lists only for Yarn 1 or not at all. The check now reads on past zero blocks and non-header blocks, through every gzip member; nothing in that tail fails for being unreadable, so the only new refusals are a real second entry or a limit met there.

What it does not change

  • The jar reader.
  • Agent-mode apply and get: they do not use these readers since v5 removed the diff-archive path, so the issue's "patch package / diff archives" row is about what now reads whole npm tarballs and sdists.
  • The strict reader used when vendor reuses or re-downloads a committed tarball still stops at the first zero block, so a re-run of vendor would reuse a tarball that vendor --check and vex now refuse. Left for a follow-up.
  • Other limits, not touched: the registry extractors' 128 MiB per entry and 60,000 entries, the directory inventory's 10,000 files, the 64 MiB per file of the .nupkg and jar blob harvest.

For the maintainers to decide

  1. 512 MiB or 1 GiB. 512 MiB refuses mkl and tensorflow-cpu. Raising it is one constant, but reading only the members a check needs (streaming) should come first: peak memory is the archive plus what it inflates.
  2. No per-member limit. A 256 MiB limit would admit xgboost with 7% headroom and refuse _catboost.so (281.9 MiB).
  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.

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; nine shadowing shapes and ten clean ones for the tail of a tarball.
  • 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, and past the first zero block and gzip member.
  • Run locally: cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, core lib (8,690 passed), the CLI lib and 19 CLI test binaries covering vendor, repair, vex, the takeover suites and mode migration (all passed). Not run: Windows, and pnpm and Bun were not probed for the tail shapes.

🤖 Generated with 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant