Skip to content

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

Backlog

Description

[agent] Found by the architecture refactor routine while checking what each size limit does when a real package is over it. Run on main at cfc870f with the binary built from it, against the repository's own vendor-service fixture (tests/prebuilt_common), with npm 10.9.9, pnpm 10.28.0, Yarn 1.22.22, Bun 1.4.4 and Node 22.

Problem

vendor --check, vex and repair read a committed npm tarball through two functions of core patch/package.rs. They stop reading before the package managers do, in three places, and raise no error. One of the three is their size limit, 64 MiB of unpacked data (MAX_TOTAL_DECOMPRESSED_BYTES, line 20), and that limit also turns away honest large packages with a false reason.

1. The check stops reading a tarball where the installers read on. vendor --check, vex and repair check that a committed tarball holds no second entry an installer would extract over a patched file (vendor_artifact_non_canonical, by shadowed_member from #2120). The contract says what that check is for: such a tarball "can hold the patched file where it is checked and install the original". The check does not see a second entry in three places:

Where the second package/index.js sits Tarball on disk vendor --check, vex Installs the second entry
after padding files, exactly 64 MiB into the tar stream 693 kB verified, not_affected npm 10.9.9, pnpm 10.28.0, Yarn 1.22.22, Bun 1.4.4
after the tar end-of-archive marker 259 bytes verified, not_affected Yarn 1.22.22
in a second gzip member 340 bytes verified, not_affected Yarn 1.22.22

At 64 MiB the tar parser sees the end of its input, and it takes an end of input between two entries for the end of the archive: everything after is never read and no error is raised. The other two are where the reader stops by design (the first zero block, the first gzip member) and Yarn 1's extractor does not.

2. An honest package over the limit cannot be vendored, and the reason given is false. When the limit falls inside an entry, the read fails. vendor turns every failed read into "prebuilt tarball for … does not carry the patched files at their recorded paths", which blames the patch service for a tarball that does carry them. Packages of that size exist and have advisories (npm view <pkg> dist.unpackedSize dist.fileCount):

Package Unpacked Files
next@13.5.6 72.3 MB 5,781
next@14.2.3 86.2 MB 6,303
next@15.1.0 120.6 MB 6,873
aws-sdk@2.1692.0 98.2 MB 2,287
plotly.js@2.25.2 86.8 MB 1,155
monaco-editor@0.47.0 92.2 MB 1,420

The limit is 67.1 MB. The same readers also refuse any single file over 16 MiB and any tarball of more than 10,000 entries.

Who it hurts: for the first, a team that relies on vendor --check in CI and on the VEX document to vouch for the tarballs committed under .socket/vendor/, which nobody can review by eye. For the second, anyone who vendors a patch for a large package: the run fails and the message sends them to the wrong place.

Evidence

The reader

A twin of the existing unit test shadowed_member_judges_only_the_listed_files (core patch/package.rs, line 861), with padding files before the second package/index.js. Its output on main:

$ cargo test -p socket-patch-core --lib -- probe_shadow_past --nocapture
boundary at the cap: tgz 65709 bytes; shadowed_member = Ok(None); read_archive_bytes_to_map = Ok((7, Some("patched")))
boundary one block before the cap: tgz 65708 bytes; shadowed_member = Err("archive I/O error: unexpected EOF during skip"); read_archive_bytes_to_map = Err("archive I/O error: unexpected EOF during skip")
control: 48 MiB of padding: tgz 49354 bytes; shadowed_member = Ok(Some("index.js")); read_archive_bytes_to_map = Ok((7, Some("original")))

assertion `left != right` failed: at the cap: the shadowing entry was not seen
  left: Some(None)
 right: Some(None)
test patch::package::tests::probe_shadow_past_the_decompression_cap ... FAILED

With 48 MiB of padding the second entry is found and the map holds its bytes. With the second entry's header at exactly 64 MiB, shadowed_member returns Ok(None) and the map holds the first entry's bytes, as if the archive ended there. One block earlier both calls fail.

The test
#[test]
fn probe_shadow_past_the_decompression_cap() {
    const FILE: u8 = b'0';
    const DIR: u8 = b'5';
    let files = vec["package/index.js".to_string()];
    // 8 blocks: three headers with one data block each, two directories.
    let head: Vec<(&str, u8, &[u8])> = vec[
        ("package/", DIR, b""),
        ("package/index.js", FILE, b"patched"),
        ("package/lib/", DIR, b""),
        ("package/lib/util.js", FILE, b"patched"),
        ("package/README.md", FILE, b"docs"),
    ];
    let cap = MAX_TOTAL_DECOMPRESSED_BYTES as usize;
    let big = vec[0u8; 16 * 1024 * 1024 - 512];
    let run = |last_pad: usize, label: &str| {
        let last = vec[0u8; last_pad];
        let mut entries = head.clone();
        entries.push(("package/pad1.bin", FILE, &big));
        entries.push(("package/pad2.bin", FILE, &big));
        entries.push(("package/pad3.bin", FILE, &big));
        entries.push(("package/pad4.bin", FILE, &last));
        entries.push(("package/index.js", FILE, b"original"));
        let tgz = raw_tar_gz(&entries);
        let shadow = shadowed_member(&tgz, &files);
        let map = read_archive_bytes_to_map(&tgz);
        eprintln!(
            "{label}: tgz {} bytes; shadowed_member = {:?}; read_archive_bytes_to_map = {:?}",
            tgz.len(),
            shadow.as_ref().map_err(|e| e.to_string()),
            map.as_ref()
                .map(|m| (m.len(), m.get("index.js").map(|b| String::from_utf8_lossy(b).to_string())))
                .map_err(|e| e.to_string()),
        );
        (shadow.ok(), map.ok().and_then(|m| m.get("index.js").cloned()))
    };
    // The second entry's header starts exactly at the cap.
    let on = cap - 8 * 512 - 3 * (16 * 1024 * 1024) - 512;
    let at_cap = run(on, "boundary at the cap");
    let before = run(on - 512, "boundary one block before the cap");
    let small = run(0, "control: 48 MiB of padding");
    assert_eq!(small.0, Some(Some("index.js".to_string())), "control");
    assert_ne!(before.0, Some(None), "one block before");
    assert_ne!(at_cap.0, Some(None), "at the cap: the shadowing entry was not seen");
    assert_ne!(at_cap.1.as_deref(), Some(&b"patched"[..]), "at the cap: read as patched");
}

Through the CLI

An npm project with one patched package, vendored with socket-patch vendor (the tarball holds package/index.js with the patched bytes and package/package.json). Each row is a fresh copy whose committed tarball gets a second package/index.js with the original bytes appended, and whose lock integrity and ledger sha256 and size are updated to match the new tarball, as the tampered states of the contract's vendor_artifact_non_canonical row are.

The second entry vendor --check vex repair --dry-run npm ci, then require('left-pad')
none (control) verified, exit 0 not_affected nothing to do PATCHED
right after the package's files vendor_artifact_non_canonical, exit 1 omitted, exit 1 would redownload (corrupt) ORIGINAL (vulnerable)
after padding files, one block before 64 MiB vendor_artifact_unreadable, exit 1 omitted, exit 1 would redownload (corrupt) ORIGINAL (vulnerable)
after padding files, exactly at 64 MiB verified, exit 0 not_affected nothing to do ORIGINAL (vulnerable)
after the end-of-archive marker verified, exit 0 not_affected nothing to do PATCHED (npm stops there too)
in a second gzip member verified, exit 0 not_affected nothing to do PATCHED (npm stops there too)

What each installer makes of the four tarballs, installed as a file: dependency into an empty project with an empty cache:

Tarball npm 10.9.9 pnpm 10.28.0 Yarn 1.22.22 Bun 1.4.4
as vendored PATCHED PATCHED PATCHED PATCHED
second entry exactly at 64 MiB ORIGINAL ORIGINAL ORIGINAL ORIGINAL
second entry after the end-of-archive marker PATCHED PATCHED ORIGINAL PATCHED
second entry in a second gzip member PATCHED PATCHED ORIGINAL PATCHED

The same two rows in a Yarn 1 project vendored with socket-patch vendor (yarn.lock wired to the tarball, its sha1 fragment and integrity updated with the tarball):

$ socket-patch vendor --check; echo "exit $?"
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified
exit 0
$ socket-patch vex --output vex.json --product pkg:generic/app@1
Wrote OpenVEX document with 1 statement to vex.json
$ yarn install --frozen-lockfile --ignore-scripts && node -p "require('left-pad')"
Done in 0.10s.
ORIGINAL (vulnerable)

The 64 MiB row in full, in the npm project (the tarball is 693 kB on disk):

$ socket-patch vendor --check; echo "exit $?"
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified
exit 0
$ socket-patch vex --output vex.json --product pkg:generic/app@1; echo "exit $?"
Wrote OpenVEX document with 1 statement to vex.json
exit 0
$ jq -r '.statements[] | "\(.status) | \(.impact_statement)"' vex.json
not_affected | Patched via Socket patch 11111111-2222-4333-8444-555555555555 (vendored)
$ socket-patch repair --dry-run | head -1
All blobs are present locally.
$ npm ci --ignore-scripts && node -p "require('left-pad')"
added 1 package in 434ms
ORIGINAL (vulnerable)
$ socket-patch vex --output vex.json --product pkg:generic/app@1; echo "exit $?"
Warning: pkg:npm/left-pad@1.3.0: the installed tree does not match its vendored artifact; the attestation is based on the committed .socket/vendor artifact (the project's lockfile or package-manager config wires it in), but the live tree carries different bytes — re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement to vex.json
exit 0
$ socket-patch vendor; echo "exit $?"
1 package is already vendored; nothing to do.
exit 0

After the install, vex still attests the package and tells the user to re-run the install, which installs the original file again.

An honest large package

The same project with an installed copy of the package that holds five 14 MiB files beside index.js, 73.4 MB in all. The fixture service serves the patched tarball:

$ tar tzvf left-pad-1.3.0.tgz | awk '{print $3 "\t" $6}'
14680064	package/dist/chunk1.js
14680064	package/dist/chunk2.js
14680064	package/dist/chunk3.js
14680064	package/dist/chunk4.js
14680064	package/dist/chunk5.js
27	package/index.js
56	package/package.json
$ tar xzOf left-pad-1.3.0.tgz package/index.js
module.exports = 'PATCHED'

$ socket-patch vendor; echo "exit $?"
Error: Failed to vendor pkg:npm/left-pad@1.3.0: prebuilt tarball for left-pad@1.3.0 does not carry the patched files at their recorded paths
Vendored 0 packages; 1 failed.
exit 1
$ socket-patch vendor --json | jq -c '.events[]'
{"action":"failed","purl":"pkg:npm/left-pad@1.3.0","errorCode":"apply_failed","error":"prebuilt tarball for left-pad@1.3.0 does not carry the patched files at their recorded paths","cause":"unclassified"}

The tarball carries the patched file at its recorded path.

Cause

  • read_archive_from_reader (core patch/package.rs, line 292) and shadowed_member (line 230) wrap the gzip stream in take(MAX_TOTAL_DECOMPRESSED_BYTES). The comment says "Reads beyond the limit yield EOF, which the tar parser surfaces as a truncated-archive error". That holds only when the limit falls inside an entry. The limit is a multiple of the tar block size, so it can fall between two entries, and there the parser ends the archive without an error.
  • Both functions stop at the first zero block, as tar readers do unless told to go on, and GzDecoder reads the first gzip member only. Yarn 1 extracts what follows either one (measured above; its source was not read). The comment on shadowed_member lists what the installers do that the decoder does not (they strip any first segment, extract links, let a later entry win). Reading past the end marker and into further gzip members is not on that list.
  • Every other bounded read in core takes one byte more than its limit and fails when it gets it: the wheel reader beside this one (core vendor/verify.rs, line 801, "+1 so an entry that would exceed the remaining budget reads one byte past it and is rejected, rather than truncating silently"), and more than a dozen take(MAX + 1) sites. Three sites take exactly the limit: the two above and walk_tar_gz (core vendor/registry_fetch.rs, line 1272, at 512 MiB), which extracts a registry tarball to disk.
  • tgz_bytes_match_after_hashes (core vendor/npm_common.rs, line 566) maps any reader error to false, and its caller (line 454) prints "does not carry the patched files" for false. The verifier (core vendor/verify.rs, lines 215 to 223) maps any reader error to vendor_artifact_unreadable, which vendor --check words as "cannot be read … run socket-patch repair to restore it".
  • Hosted mode reads the served tarball through the same function for a Yarn 1 pin, and for a Yarn Berry pin of a package with a bin: map (core hosted/npm_manifest.rs, line 19; CLI commands/scan/hosted.rs, lines 1928 and 1971). A package over the limit loses its patch there with npm_tarball_unavailable or npm_manifest_unavailable and the detail "hosted tarball is not a readable npm package: archive I/O error: unexpected EOF during skip". Read, not run: the error text is the one the test above prints for a limit inside an entry.
  • The limits themselves were written for patch archives ("Real socket-patch archives are tiny (kilobytes); 64 MiB is a generous ceiling", lines 18 to 19, from feat(patch): add package- and diff-level patch sources #67). Vendored mode later began reading whole package tarballs through the same functions (Harden vendored-mode trust in patch-service artifacts #249). Whole packages have their own limits elsewhere: 512 MiB unpacked, 128 MiB per entry and 60,000 entries (core vendor/registry_fetch.rs, lines 21 to 30, "wider than patch/package.rs's patch-archive caps because these are full upstream packages").
  • Jars had the same pair of problems, and Read jars within jar-sized limits and compare patched jars member by member #2132 fixed them for jars: a reader with jar-sized limits, and a verdict of its own for a jar past them (vendor_artifact_too_large, "so its contents were not checked"). Tarballs and wheels were left on the old limits and the old messages.

Planned fix

  1. One bounded gzip reader for the three tar sites that fails on the first byte past its limit with an error that says so, and no bare take(limit) left. An archive that reaches the limit is then never read as complete.
  2. The second-entry check reads what any of the four installers reads: every gzip member, and past the end-of-archive marker. An entry there that lands on a patched file is vendor_artifact_non_canonical, like any other second entry. Zero padding after the marker, which npm pack writes, stays fine.
  3. A "too large" error that reaches the user: vendor says the tarball unpacks to more than the limit instead of "does not carry the patched files", and vendor --check and vex report vendor_artifact_too_large, as they do for jars, instead of "cannot be read". The wheel reader gets the same wording (pypi.rs, line 4129, prints "does not carry the patched files" for a wheel over 64 MiB or 10,000 entries), and so do the two hosted skips.
  4. A question for a maintainer, not part of the first slice: should a vendored package tarball be read within the whole-package limits registry_fetch.rs already has? That would let a package such as next be vendored. It also lets one tarball take up to 512 MiB of memory while it is checked.

The unit test above, a twin for read_archive_bytes_to_map_strict, and one case each for the end marker and the second gzip member go in with the fix.

Not checked

  • Whether the patch service serves a patch for a package over the limit. The patch API is not reachable from the sandbox this ran in.
  • Yarn Berry, and other versions of the four installers that ran.
  • The readers that reuse a committed tarball (vendor/reuse.rs, line 242) and check a re-download (vendor/redownload.rs, line 185) call the same decoder; they were read, not run, beyond the vendor run above that keeps the tampered tarball as "already vendored".
  • The wheel reader and walk_tar_gz were read, not run. A wheel cannot be read short this way: its reader goes by the zip directory and counts what it inflates.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. changed the title [-]A vendored npm tarball is read as ending at 64 MiB: vendor --check and vex miss a later entry, and a large package is refused for a false reason[/-] [+]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[/+] on Nov 28, 2026
  3. mikolalysenko commented on Dec 1, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Where this stands after #2410, and what was learned about the rest.

    #2410 covers the limit rows of this issue. A limit is an error that names the limit (no reading short), the limits are raised, and a second entry at the old 64 MiB mark is seen. The other two rows of the table (a second entry after the end-of-archive marker, or in a second gzip member) are not in it: on that PR the check reads exactly as far as main does.

    Work on those rows exists on the branch fix/npm-tarball-canonical-shape and is not ready. It makes the check walk the tar stream header by header, accept one shape of tarball and refuse everything else (vendor_artifact_non_canonical), and runs it on the served, the reused and the re-downloaded tarball as well as in vendor --check and vex. Why it was taken out of #2410:

    1. It refuses a real tarball from the patch service. ejs@3.1.6 is served with the upstream top directory ejs-v3.1.6/, the branch demands package/, and with the check running at vendoring time the patch could not be vendored at all. main vendors and verifies it (and has a related defect of its own, repair cannot restore a vendored npm tarball whose top directory is not package/ (ejs@3.1.6), and every vendored scan downloads it again #2423).
    2. Its header rules were never exercised by service data. The 35 service tarballs it was run on hold only file and directory headers: no PAX header, no long name, no link. The rules accept a PAX header with one path record and refuse, among others, a second path record and an empty linkpath, which a re-pack of an upstream entry could write.
    3. It did not converge. Two review passes and the probing in between each found shapes the installers read differently from the check. Bun was not probed.

    What the probes showed, with npm 11.19.1, Yarn 1.22.19 and pnpm 11.27.0 installing a tarball as a file: dependency. For the first table, vendor --check and vex on main verified all five tarballs. The shapes in the second and third tables were each accepted by the branch's walking check before the rule for it was added; main's verdict on them was not recorded row by row.

    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
    Header before the second entry npm installs Yarn 1 installs
    L or x without ustar or GNU magic the second the second
    after a zero block: L or x, then a non-header block the second fails
    after a zero block: two L headers the second the second
    old GNU long name N the second the second
    old PAX header X the second fails
    x with two path records the second the second
    x with an empty line before path the second the first
    x with path, then L the first the second
    global g with path, then any x the first the second
    L larger than 1 MiB the first the second
    Shape of the patched file's own header npm Yarn 1 pnpm
    size with a space and U+0085 before its digits original original original
    checksum with U+0085 before its digits original fails fails
    a file whose header has a link name original patched patched
    link-name field holding NUL, newline, text original patched patched
    own header with no name, behind a PAX path patched patched no index.js
    path prefix under the GNU magic patched wrong place wrong place

    So the first three rows of the first table reach npm itself, not only Yarn 1.

    For the owner to decide before anyone continues: whether vendor --check and vex should refuse every tarball that is not in one canonical shape (strong, but each rule is a possible false refusal of a tarball the service serves), or only look for a second entry over a patched file in more places. Either way the rule for the top directory has to accept what the service serves, and a service tarball with a path long enough to need a PAX header should be in the test set first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions