Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
e647a94
Read tarballs, wheels and nupkgs within shared limits, and make a lim…
mikolalysenko Dec 1, 2026
736a05f
Check the archive limits through the CLI and word the vex omission fo…
mikolalysenko Dec 1, 2026
099dd6f
Document the archive limits and the too-large verdict for tarballs an…
mikolalysenko Dec 1, 2026
60f8b94
Fail a tarball extraction past its unpacked cap instead of extracting…
mikolalysenko Dec 1, 2026
04e6fdf
Look for a second entry over a patched file as far as the installers …
mikolalysenko Dec 1, 2026
6338110
Reserve a member's buffer as it arrives, and call an artifact too lar…
mikolalysenko Dec 1, 2026
1a8b66b
Take a header that names a tarball entry only in the shape every inst…
mikolalysenko Dec 1, 2026
55b009a
Take the second-entry check work out of this change
mikolalysenko Dec 1, 2026
3602c9d
Hold a package to one set of size limits on every path, and raise them
mikolalysenko Dec 1, 2026
4c92da3
Merge origin/main into fix/wheel-tgz-size-caps
mikolalysenko Dec 1, 2026
32bf4a3
Reserve nothing on a declared size, and read one member where one is …
mikolalysenko Dec 1, 2026
0eab05d
Test the caps against ones a test can reach, and say how far a tarbal…
mikolalysenko Dec 1, 2026
cb1d99d
Put the doc comment of PAST_THE_LIMITS back above it
claude Dec 2, 2026
301a394
Put the doc comment of harvest_zip_blobs back above it
claude Dec 2, 2026
e15c6dd
Merge remote-tracking branch 'origin/main' into fix/wheel-tgz-size-caps
mikolalysenko Dec 2, 2026
8fbbf77
Merge branch 'fix/wheel-tgz-size-caps' of github.com:SocketDev/socket…
mikolalysenko Dec 2, 2026
f03cc4d
Merge origin/main into fix/wheel-tgz-size-caps
claude Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,12 @@ path. Without hosted pins the no-manifest no-op below is unchanged.

Coverage includes npm (all lock flavors), Python wheels and source distributions, Cargo crates, Go module zips, Composer dist zips, RubyGems, NuGet packages and JVM jars. Directory artifacts are extracted and receive only the existing package-manager layout transformations. RubyGems requires the server's separately verified `gem-stub-gemspec`; a missing or invalid stub is a failure. A gem whose `Gemfile.lock` holds platform-suffixed entries (`nokogiri (1.18.10-x86_64-linux-gnu)`) is taken as the patch's prebuilt platform gems instead: for each locked platform the server's `gem-platform` artifact and its `gem-platform-stub-gemspec` (each carries its `platform`), both verified like the ruby gem and its stub. Which prebuilds exist is read from the package reference alone, and the ruby gem it also names is not downloaded. While the server lists no prebuild for a locked platform nothing is downloaded and the gem is skipped (`vendor_prebuilt_platform_pending`). A prebuild need not ship any of the patch's files (a patch of `patches/**` or `dependencies.yml` lives entirely in the rebuilt binaries): its integrity check against the digest the server states for that platform is mandatory and is what vouches for it, while a patched file it does ship that is not the patched one is a `vendor_prebuilt_required` failure. Yarn Berry checksums come from server metadata. Hosted Berry rollback retrieves upstream checksum metadata from `/upstream/npm/<uuid>.json` and checks its package identity and upstream integrity against the registry; the CLI does not recreate the Berry zip.

**Archive limits.** An npm tarball, a Python wheel or source distribution and a `.nupkg` are decoded in memory within fixed limits, counted on the bytes actually inflated and on the archive's own entry count (a size an archive declares only refuses it sooner): 200,000 entries, and per read of one archive 1 GiB unpacked and at most 100 times the archive's own size (an archive smaller than 655 KiB may still unpack to 64 MiB). For a tarball the bytes are those of the tar stream, each entry's 512-byte header and padding included. One file may be as large as what is left of its archive's allowance. What is unpacked is held in memory, so 1 GiB plus the archive itself is what checking one archive may take: an npm tarball of 17 MiB that unpacks to 1,000 MiB was measured at 1,079 MiB resident for `vendor`, 1,055 MiB for `vendor --check` and 1,059 MiB for `vex`. These are the limits wherever a package is read, unpacked or downloaded, so that one path does not refuse for its size what another takes: the registry extractors, which write to disk, unpack 200,000 entries and 1 GiB with no smaller limit on one entry (they were 60,000 entries, 512 MiB and 128 MiB for one entry: `@next/swc-linux-x64-gnu` holds a file of 136 MiB); a download is at most 256 MiB from the patch service and from a registry (a registry's was 128 MiB); the inventory of a committed directory covers 200,000 files (it was 10,000: the wheel of `ansible` 11.1.0 holds 21,105); a patched file recovered from a committed zip may be as large as that zip may unpack to (it was 64 MiB); and a jar has the same 200,000 entries, 1 GiB and 100 times its own size.

An archive past a limit is `vendor_artifact_too_large`, and the detail names the limit and, where the archive's own headers say, the count it holds or the size it unpacks to: `it unpacks to 1100 MiB, over the limit of 1024 MiB for one archive`; `it unpacks to more than 64 MiB, over 100 times its own size (80 KiB) and the 64 MiB every archive may use`; `it holds 200001 entries, over the limit of 200000`. That is a refusal when vendoring a Python distribution; the failure detail when vendoring an npm package (`the patch service's tarball for <name>@<version> cannot be checked: …`, under the `apply_failed` code its failures carry); the `vex` omission tag and the `vendor --check` reason for a committed artifact (`… is past the limits archives are read within: …`), which `repair` restores from the recorded one; and the error of a `repair` whose own download is past them. In hosted mode a served npm tarball past a limit skips its patch (`npm_tarball_unavailable` / `npm_manifest_unavailable`) with the same detail. A committed wheel, source distribution or npm tarball larger than 512 MiB on disk is not read at all and is too large as well (`it is 513 MiB on disk, over the 512 MiB a committed artifact is read up to`), and so is a tarball with a file the machine has no memory to hold (`it holds a member of 300 MiB, more than there is memory for`): the size a file's header declares reserves nothing before its content arrives. A limit that is met is always that error and never the end of the archive: the check for a second entry over a patched file (`vendor_artifact_non_canonical`) reads what the decoder reads, one gzip member up to the first all-zero block of its tar stream, and within that no entry sits beyond a limit unseen. Neither reads what follows that block, or a second gzip member, which some installers do (#2330).

Measured on the registries, within the 256 MiB a download from the patch service may be: npm `onnxruntime-node` 1.20.1 unpacks to 180 MiB and `@mui/icons-material` 6.2.1 holds 31,858 files; PyPI `paddlepaddle` 2.6.2 unpacks to 430 MiB, `xgboost` 2.1.3 holds one file of 239 MiB, and `ansible` 11.1.0 holds 21,105 files. The two largest wheels measured within that download size are within the limit: `mkl` 2025.0.1 (521 MiB) and `tensorflow-cpu` 2.18.0 (946 MiB, 603 MiB of it one file). At the 512 MiB the limit was, both were refused. Jars are read without being held in memory and have limits of their own ([Vendored JVM support](#vendored-jvm-support-v5)).

Agent runs fetch patch content as per-file blobs (v5.0 removed `--download-mode` and the diff archive path). Vendored runs retain patch records in memory and embed them in the vendor ledger, without staging blobs. N-API and the hosted in-memory engine remain supported for callers such as the future GitHub App.

**Vendored artifact repair (v5.0)**: `repair` checks the committed artifact and downloads a replacement for the same UUID into a temporary location. Before replacement it checks transfer integrity, patched-member hashes, and the original ledger's SHA-256 and size (file artifacts) or complete file inventory (directory artifacts). JVM repair also reproduces and checks the recorded repository metadata. Different downloaded bytes or inventories are refused; the old files, ledger and lockfiles remain intact. No installed package or patch blobs are required, and none are used to construct a replacement. Missing directory inventories cannot establish an exact replacement and require explicit re-vendoring.
Expand Down Expand Up @@ -2703,7 +2709,7 @@ command's integration tests check its output.
| `vendor_unwired` | `skipped` | vex: a vendor-ledger entry whose committed artifact no lockfile/config wires any more (reverted lock, leftover ledger or artifact). Applies under `--no-verify` too. |
| `redirect_unwired` | `skipped` | vex: a hosted record (this run's, or a pre-v5 redirect ledger's) whose hosted patch no lockfile wires any more (and no manifest entry owns the purl). Applies under `--no-verify` too. |
| `wiring_conflict` | `skipped` | vex (manifest-less): the lockfiles wire one package to two or more different patches (e.g. a stale sibling lock); which one the build installs is undecidable, so none is attested. |
| `hash_mismatch` / `not_applied` / `file_not_found` / `unreadable_file_mode` / `package_not_found` / `no_files` / `vendor_*` | `skipped` | vex: verification omissions — the installed copy (agent / hosted) or the committed artifact (`vendor_hash_mismatch`, `vendor_artifact_missing`, `vendor_artifact_unreadable`, `vendor_artifact_too_large`, `vendor_artifact_non_canonical`, `vendor_inventory_mismatch`, `vendor_uuid_mismatch`, `vendor_path_unsafe`) does not carry the patched bytes, or nothing is installed. `vendor_artifact_too_large` (jars): the committed jar is past the limits jars are read within (see [Vendored JVM support](#vendored-jvm-support-v5)), so its contents were not checked (`vendor --check` reports it as a corrupt artifact that `repair` restores from the recorded jar). `vendor_artifact_non_canonical`: a committed npm tarball holds a second entry the installers would extract over one of the patch's files — the same path under another top-level directory, a second or case-variant spelling of the name, a link, or a non-directory where one of the file's parent directories must be. npm-family installers strip the first path segment whatever it is, extract links as well as files and let a later entry overwrite an earlier one, so such a tarball can hold the patched file where it is checked and install the original (`vendor --check` reports it as a corrupt artifact that `repair` restores). Only the patch's own files are judged: an upstream tarball with a link, a non-ASCII name or a case twin elsewhere, which vendoring accepts, keeps verifying. `vendor_lock_pin_mismatch` (bun): the artifact holds the patch, but the `bun.lock` tuple or `bun.lockb` record that resolves to it carries a digest that is not the tarball's sha512 (a pin under any other algorithm is not one vendoring wrote), so an install does not deliver it — Bun 1.3.10+ fails the integrity check on a cold cache, and Bun 1.4 keys its tarball cache by that digest and installs whatever cached tarball has it. `vendor --check` reports the same as a wiring failure (exit 1) with the remedy, re-running `scan --mode vendored`, which rewrites the pin. A tuple without a digest (the 2-tuple Bun 1.1.39 to 1.3.9 re-save) has no pin to be wrong. `vendor_manifest_unverifiable`: a vendored vlt directory verified without its vendor ledger (from `vlt-lock.json` alone) holds a `package.json` with its devDependencies stripped, and the patched `package.json` blob is not in `.socket/blobs`, so it cannot be checked. A lockfile-pinned hosted reference with nothing installed attests instead of `package_not_found` (see "Manifest-less VEX"). |
| `hash_mismatch` / `not_applied` / `file_not_found` / `unreadable_file_mode` / `package_not_found` / `no_files` / `vendor_*` | `skipped` | vex: verification omissions — the installed copy (agent / hosted) or the committed artifact (`vendor_hash_mismatch`, `vendor_artifact_missing`, `vendor_artifact_unreadable`, `vendor_artifact_too_large`, `vendor_artifact_non_canonical`, `vendor_inventory_mismatch`, `vendor_uuid_mismatch`, `vendor_path_unsafe`) does not carry the patched bytes, or nothing is installed. `vendor_artifact_too_large`: the committed artifact is past the limits it is read within (an npm tarball, a Python wheel or source distribution, a `.nupkg`: see "Archive limits" under the [Vendor command contract](#vendor-command-contract); a jar: see [Vendored JVM support](#vendored-jvm-support-v5)), so its contents were not checked (`vendor --check` reports it as a corrupt artifact, naming the limit, that `repair` restores from the recorded artifact). A limit that is met is always this tag, never an artifact read up to the limit: a tarball is read to its end-of-archive marker or not vouched for. `vendor_artifact_non_canonical`: a committed npm tarball holds a second entry the installers would extract over one of the patch's files — the same path under another top-level directory, a second or case-variant spelling of the name, a link, or a non-directory where one of the file's parent directories must be. npm-family installers strip the first path segment whatever it is, extract links as well as files and let a later entry overwrite an earlier one, so such a tarball can hold the patched file where it is checked and install the original (`vendor --check` reports it as a corrupt artifact that `repair` restores). Only the patch's own files are judged: an upstream tarball with a link, a non-ASCII name or a case twin elsewhere, which vendoring accepts, keeps verifying. `vendor_lock_pin_mismatch` (bun): the artifact holds the patch, but the `bun.lock` tuple or `bun.lockb` record that resolves to it carries a digest that is not the tarball's sha512 (a pin under any other algorithm is not one vendoring wrote), so an install does not deliver it — Bun 1.3.10+ fails the integrity check on a cold cache, and Bun 1.4 keys its tarball cache by that digest and installs whatever cached tarball has it. `vendor --check` reports the same as a wiring failure (exit 1) with the remedy, re-running `scan --mode vendored`, which rewrites the pin. A tuple without a digest (the 2-tuple Bun 1.1.39 to 1.3.9 re-save) has no pin to be wrong. `vendor_manifest_unverifiable`: a vendored vlt directory verified without its vendor ledger (from `vlt-lock.json` alone) holds a `package.json` with its devDependencies stripped, and the patched `package.json` blob is not in `.socket/blobs`, so it cannot be checked. A lockfile-pinned hosted reference with nothing installed attests instead of `package_not_found` (see "Manifest-less VEX"). |
| `not_applied` / `hash_mismatch` / `file_not_found` / `no_matching_variant` / `unreadable_file_mode` | `failed` | `apply --check` (v5.0): an installed copy of the patch does not verify (still unpatched; neither the original nor the patched bytes; a patched file missing; a copy of a release-variant base that holds none of the manifest's variants, keyed by the base purl; a file entry whose `mode` this release cannot read, see "File permissions as part of a patch"). Exit 1, status `partialFailure`. The `no_matching_variant` reason says that `apply` leaves such a copy as it is, and for a gem names `bundle pristine <gem>` and the `apply` to run after it. |
| `no_matching_variant` | `failed` | apply, and the apply that `get` / `scan --mode agent` run (gem, PyPI): an installed copy of a release-variant base (a base whose manifest records are qualified, or a gem build beside another build of its version) whose files match none of the manifest's records for it and which holds one of the patch's files with other content: an edited copy, or another build of the version. (A copy that holds none of the files its records are matched by is not told to belong to them: they stay `package_not_installed`, and the run still exits 1.) Keyed by the base purl, one event per copy. The copy is left as it is and the run exits 1 (`partialFailure`). `error` names the copy and the file that holds neither side of a record; for a gem it adds `bundle pristine <gem>` (or `gem pristine <gem>`), which restores an edited copy to the published gem. The copy is installed, so no record of the base is `package_not_installed` in that run. |
| `redirect_unconfirmed` | `skipped` (`details.mode: "hosted"`) | hosted `scan` / `get` (v5.0, additive): the patch was granted but no lockfile entry pinning it could be rewritten. The status and exit code are unchanged for now, pending the open hosted exit-policy decision (#704); `--silent` hides the human line. |
Expand Down
13 changes: 10 additions & 3 deletions crates/socket-patch-cli/src/commands/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,9 +2860,16 @@ fn omission_phrase(reason: &str) -> &'static str {
"vendor_artifact_missing" => "the vendored artifact is missing",
"vendor_artifact_unreadable" => "the vendored artifact cannot be read",
"vendor_artifact_too_large" => {
"the vendored jar is past the limits jars are read within (200,000 entries, or 1 GiB \
and 100 times its own size inflated), so its contents were not checked; run \
socket-patch repair to restore the recorded jar"
// The numbers are the limits themselves, not a copy of them.
static PHRASE: std::sync::OnceLock<String> = std::sync::OnceLock::new();
PHRASE.get_or_init(|| {
format!(
"the vendored artifact is past the limits it is read within ({}), so its \
contents were not checked; run socket-patch repair to restore the recorded \
artifact",
socket_patch_core::vendor::archive_limits_summary()
)
})
}
"vendor_artifact_non_canonical" => {
"the vendored tarball holds a second entry the package manager would extract \
Expand Down
Loading
Loading