Skip to content

vendor --check and vex verify a committed jar that holds a patched member twice, and a shaded Maven build ships the original #2332

Backlog

Description

[agent] Found by the architecture refactor routine while checking which safety gates of the vendored-artifact verifier a test can catch. Run on main at cfc870f with the binary built from it, against the repository's own offline JVM fixtures (tests/vendor_jvm_cli.rs), with OpenJDK 21, Maven 3.9.11 and Gradle 8.14.3.

Problem

vendor --check, vex and repair read a committed jar by member name, and of two entries with one name they read the last (core patch/jar_members.rs, lines 21 to 23 and 168 to 187). A jar that holds a patched member twice, the original bytes first and the patched bytes last, therefore verifies. Not every build takes the last entry: maven-shade-plugin takes the first. So the check and the VEX document vouch for a jar from which a shaded build ships the original file.

This is the jar twin of vendor_artifact_non_canonical, which #2120 added for npm tarballs. The contract's reason for that row is that such an archive "can hold the patched file where it is checked and install the original". The npm reader refuses any second entry on a patched file's path (shadowed_member, core patch/package.rs, line 204). The wheel reader refuses a second entry of any name (read_zip_to_map with strict, core vendor/verify.rs, line 778, from #250). The jar reader, written later (#2132), accepts one and picks.

Who it hurts: a team that relies on vendor --check in CI and on the VEX document to vouch for the jars committed under .socket/vendor/, and that ships a shaded jar. It takes a commit that replaces the jar and its recorded hashes, which is the state vendor --check exists to catch. No jar that vendor writes has a name twice.

Evidence

What each build takes

Two jars, each with p/Hello.class twice: one version of the class prints PATCHED, the other ORIGINAL.

Reader original first, patched last patched first, original last
java -cp (OpenJDK 21) PATCHED ORIGINAL
javac -cp, then java -cp PATCHED ORIGINAL
Gradle 8.14.3: JavaExec, and a zipTree fat jar under DuplicatesStrategy.INCLUDE and EXCLUDE PATCHED ORIGINAL
Maven 3.9.11, maven-assembly-plugin 3.7.1 jar-with-dependencies PATCHED ORIGINAL
Maven 3.9.11, maven-dependency-plugin 3.6.1 unpack-dependencies PATCHED ORIGINAL
Maven 3.9.11, maven-shade-plugin 3.5.1 ORIGINAL PATCHED
socket-patch (vendor --check, vex, repair) patched original

The module comment says "the zip crate and java.util.zip.ZipFile both resolve a name to the last entry that carries it". That holds. The shade plugin's uber jar holds the name once, with the bytes of the first entry.

Through the CLI

The suite's Maven reactor and Gradle projects, each with one patch that changes META-INF/NOTICE.txt, vendored with socket-patch vendor. Each row is a fresh copy whose committed jar is replaced, and in which every recorded hash follows the file it names: the jar's .sha1, the tree marker socket-patch.vendor.json, gradle-index.tsv and the ledger.

META-INF/NOTICE.txt in the committed jar vendor --check vex repair --dry-run
once, patched (as vendored) verified, exit 0 not_affected nothing to do
twice: original first, patched last verified, exit 0 not_affected nothing to do
twice: patched first, original last vendor_hash_mismatch, exit 1 omitted, exit 1 would redownload (corrupt)
once, original vendor_hash_mismatch, exit 1 omitted, exit 1 would redownload (corrupt)

The Maven and the Gradle project give the same four rows.

One project, end to end

The Maven project of the second row, with a class in module a that prints the META-INF/NOTICE.txt it finds on its class path, and the shade plugin on that module:

$ socket-patch vendor --check; echo "exit $?"
pkg:maven/org.example/foo@1.0: committed artifact and wiring verified
exit 0
$ socket-patch vex -O vex.json --product pkg:generic/x@1
Wrote OpenVEX document with 1 statement to vex.json          (not_affected)
$ unzip -l .socket/vendor/maven2/org/example/foo/1.0-socket.1d3c1fd2/foo-1.0-socket.1d3c1fd2.jar
       22  META-INF/MANIFEST.MF
       11  META-INF/NOTICE.txt
       19  META-INF/NOTICE.txt
$ mvn -q package
$ java -cp a/target/classes:.socket/vendor/maven2/org/example/foo/1.0-socket.1d3c1fd2/foo-1.0-socket.1d3c1fd2.jar Show
NOTICE foo | PATCHED |
$ java -cp a/target/a-1.jar Show          # the shaded jar
NOTICE foo |

The same project as vendored prints NOTICE foo | PATCHED | both times. The two socket-patch commands ran with --offline, as the suite runs them. vex also prints the fixture's standing warning that the local repository's copy differs from the vendored jar, as it does for the project as vendored.

A unit test

A twin of nupkg_and_jar_members_verified_as_zip (core vendor/verify.rs), with the member twice. It fails on main:

$ cargo test -p socket-patch-core --lib -- a_patched_member_held_twice --nocapture
commons-text-1.10.0.jar: original first, patched last = Ok(()); patched first, original last = Err("vendor_hash_mismatch")
newtonsoft.json.13.0.3.nupkg: original first, patched last = Ok(()); patched first, original last = Err("vendor_hash_mismatch")

assertion `left == right` failed: commons-text-1.10.0.jar: original first, patched last
  left: Ok(())
 right: Err("vendor_artifact_non_canonical")
test vendor::verify::tests::a_patched_member_held_twice_is_not_verified ... FAILED

The second line is a vendored .nupkg, which takes the same path (see "Not checked").

The test
/// A committed jar or nupkg that holds a patched member twice is not
/// verified, whichever entry is the patched one.
#[tokio::test]
async fn a_patched_member_held_twice_is_not_verified() {
    /// A zip with `member` twice. The writer refuses a repeated name,
    /// so the second entry is written under a twin of the same length
    /// and renamed in its local header and in the central directory.
    fn write_twice(dest: &Path, member: &str, first: &[u8], last: &[u8]) {
        let twin = format!("{}~", &member[..member.len() - 1]);
        let mut zip = zip::ZipWriter::new(std::io::Cursor::new(Vec::new()));
        for (name, bytes) in [(member, first), (twin.as_str(), last)] {
            zip.start_file::<_, ()>(name, Default::default()).unwrap();
            zip.write_all(bytes).unwrap();
        }
        let mut bytes = zip.finish().unwrap().into_inner();
        let (from, to) = (twin.as_bytes(), member.as_bytes());
        let mut renamed = 0;
        let mut at = 0;
        while at + from.len() <= bytes.len() {
            if &bytes[at..at + from.len()] == from {
                bytes[at..at + from.len()].copy_from_slice(to);
                renamed += 1;
                at += from.len();
            } else {
                at += 1;
            }
        }
        assert_eq!(renamed, 2, "local header and central directory");
        std::fs::write(dest, bytes).unwrap();
    }
    let cases: &[(&str, &str, &str)] = &[
        ("maven", "commons-text-1.10.0.jar", "META-INF/NOTICE.txt"),
        ("nuget", "newtonsoft.json.13.0.3.nupkg", "LICENSE.md"),
    ];
    let mut verdicts = Vec::new();
    for (eco, leaf, member) in cases {
        let tmp = tempfile::tempdir().unwrap();
        let root = tmp.path();
        let rel = format!(".socket/vendor/{eco}/{UUID}/{leaf}");
        tokio::fs::create_dir_all(root.join(format!(".socket/vendor/{eco}/{UUID}")))
            .await
            .unwrap();
        let rec = record(UUID, member);
        let ent = entry(eco, UUID, &rel);
        write_twice(&root.join(&rel), member, b"original bytes\n", PATCHED);
        let patched_last = verify_vendored_patch_record(root, &ent, &rec).await;
        write_twice(&root.join(&rel), member, PATCHED, b"original bytes\n");
        let patched_first = verify_vendored_patch_record(root, &ent, &rec).await;
        eprintln!(
            "{leaf}: original first, patched last = {patched_last:?}; patched first, original last = {patched_first:?}"
        );
        verdicts.push((leaf, patched_last, patched_first));
    }
    for (leaf, patched_last, patched_first) in verdicts {
        assert_eq!(
            patched_last,
            Err("vendor_artifact_non_canonical".to_string()),
            "{leaf}: original first, patched last"
        );
        assert_eq!(
            patched_first,
            Err("vendor_artifact_non_canonical".to_string()),
            "{leaf}: patched first, original last"
        );
    }
}

Planned fix

Refuse a committed jar in which a patched member's name occurs more than once, as vendor_artifact_non_canonical, in the one place the jar checks share (verify_jar_members, core vendor/verify.rs, line 681). Only the patch's own members are judged, as for npm: an upstream jar with a repeated name elsewhere keeps verifying. vendor --check then reports a corrupt artifact that repair restores, and vex omits the package. A unit test beside nupkg_and_jar_members_verified_as_zip and a row in tests/vendor_jvm_cli.rs pin it. The contract's vendor_artifact_non_canonical row names npm tarballs only and gains the jar.

Not checked

  • The Gradle Shadow plugin and Spring Boot's repackaged jars: the first needs the plugin portal, which this sandbox does not reach.
  • A vendored .nupkg. It is read through the wheel reader without strict (core vendor/verify.rs, line 225), so a repeated name reads as its last entry there too. What NuGet extracts from such a package needs dotnet, which this sandbox lacks.
  • Agent mode, where the jar is the one in the local repository or the Gradle cache and nothing is committed.
  • Whether an upstream jar ever repeats the name of a member a patch changes.

Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 28, 2026
  2. added a commit that references this issue on Nov 28, 2026
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:p3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions