Skip to content

Report a multi-release jar's unpatched versioned copy of a patched class (#2199) - #2411

Merged
Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
fix/maven-multi-release-copies
Dec 1, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 13 commits into
mainfrom
fix/maven-multi-release-copies

Conversation

@mikolalysenko

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

Copy link
Copy Markdown
Collaborator

Part of #2199: the multi-release check, and documentation of the copies that are not detected (nested jars, shaded copies).

The problem

A patch record lists the jar members it changes (a/B.class). A multi-release jar can hold the same class again per Java release (META-INF/versions/9/a/B.class), and a runtime of that release or later loads that copy instead of the base entry. When the record does not list the versioned copy, the patched class is in the jar, every report says patched, and the code that runs is the old one.

What changes

A new check (patch/multi_release.rs) finds versioned copies of a patched member that do not carry the patch, and reports them under one code, multi_release_unpatched_copy:

<jar> carries an unpatched copy of <member> at <paths>; it is a multi-release jar, so a Java runtime of that release or later loads that copy, not the patched one

Mode What happens
Agent apply, member-keyed record The jar stays patched, and the patch is reported as incomplete: a failed event with the code, Patch of <purl> is incomplete: …, exit 1. Also on --dry-run and for a jar that was patched earlier
apply --check Drift under the code, exit 1
Vendored vendor / scan / get The jar is vendored; warning vendor_jvm_degraded with reason: multi_release_unpatched_copy: …; exit 0, as for classifier_unpatched_copy
vex The package's statement is withheld under the code, with a run warning that names the jar. For a vendored jar this is a plan gate, so it holds under --no-verify; a vendored jar that cannot be opened or is missing is then omitted as "could not be checked" (with verification on, its own reason stands: unreadable, too large or missing)

A copy is fine when the record lists that exact path, or when its bytes are the patched ones of the member it overrides. A versioned copy of a class the record does not change is not looked at.

What a JVM loads, read in the OpenJDK 11, 17, 21 and current sources (JarFile, ZipFile.Source) and run against OpenJDK 11.0.32, 17.0.20, 21.0.12 and 26.0.1 with 23 probe jars:

  • Versioned entries count only when the manifest's main section says Multi-Release: true (name and value in any letter case). Without it they are never read, and nothing is reported.
  • An entry is looked up under exactly META-INF/versions/<n>/<name>, <n> decimal with no leading zero, and never for a <name> under META-INF/.
  • META-INF/versions/8/ counts. The JAR specification says 8 < n and OpenJDK 11 ignores directory 8, but OpenJDK 17, 21 and 26 load it. Directories 7 and below are ignored by all four.

Cost: names come from the central directory; the manifest is inflated only when a candidate copy exists, and only candidates are hashed. The jar reader's limits are unchanged.

What it does not do

  • Hosted mode never reads the jar at scan time, so scan --mode hosted reports nothing. A hosted pin's jar is judged by vex only where a local cache holds the patched jar. It is not judged for a pin whose jar is in no cache, by the --vex of the scan --mode hosted run that wrote or confirmed the pin, or under --no-verify; in those cases the statement is written. The docs and the contract say so, and a test pins each case.
  • Whole-jar records list no members, so there is nothing to compare.
  • Nested jars (BOOT-INF/lib/, WEB-INF/lib/) and shaded or relocated copies are not detected. docs/ecosystems.md and the contract now say so.

For the maintainers to decide

  1. Agent apply exits 1 on every run for an affected patch, and the user cannot clear it: it takes a patch that also lists the versioned copy. That follows the rule that a patch only partly in effect is not a success, and it is what the gem incomplete-patch path does. I do not know how many published patches are member-keyed patches of multi-release jars; if there are many, this is worth a count before a release.
  2. Vendored stays exit 0 (the classifier precedent), so agent and vendored differ in exit status for the same jar.
  3. The hosted gap above. Closing it means downloading the jar at scan time.

Review

/code-review high found six things, fixed in the last seven commits:

  • A vendored jar gated for a versioned copy was not counted as a candidate of its purl, so a second candidate of the same purl could be attested beside the skip. No Maven input reaches that state (two patches on one release are a wiring conflict first); the fix is defensive and tested through the plan directly.
  • A doc sentence said vex writes no statement "in any mode"; the hosted cases above are now stated exactly.
  • A check that died (a panic in the zip reader, a cancelled task) was taken for "no finding" in apply. One helper now serves apply, the verifier and the vendored gate, and a check that does not finish is "could not be checked".
  • vendor and vex disagreed about a vendored jar that cannot be opened. Under --no-verify such a jar is no longer attested. This is a behaviour change: vex --no-verify used to write not_affected for a vendored JVM entry whose jar was missing.
  • Jar parsing ran on the async worker; it runs on the blocking pool now.
  • Member names are read from the central directory alone, and an entry the directory lists but nothing can read makes the jar "could not be checked" instead of clean.

One commit in the middle (5909e223b) has a failing test that the next commit fixes; the branch head is what was tested.

Tests

  • Unit tests of the JVM rules (the manifest attribute in each spelling, directories 7, 8, 9, 09, x, wrapped and unterminated manifest lines, a copy listed by the record, a copy equal to the patched member, a higher release overriding a patched versioned member, an unreadable manifest).
  • CLI: tests/gradle_agent_cli.rs (agent apply, --check, dry run) and tests/vendor_jvm_cli.rs (vendored, vendor --check, repair, vex), on offline fixtures.
  • Run locally on the head commit: cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, core lib (8,695 passed), CLI lib and 22 CLI test binaries covering agent Gradle, JVM vendoring, VEX, sbt, scala-cli and Bazel beside Maven (all passed). Not run: the suites that need a real Maven, Gradle or sbt toolchain or Maven Central, and anything on Windows, where the new awaits in the vex plan and the vendoring path make async frames larger; CI's Windows jobs are the check for that.
  • docs/ecosystems.md names log4j-api and h2 as multi-release examples, taken from the issue and not checked here.

🤖 Generated with Claude Code

…e jar

A patch record lists the jar members it changes. A multi-release jar may
hold a class again per Java release under META-INF/versions/<n>/, and a
runtime of that release or later loads that copy instead of the base entry.
Nothing looked at those entries, so a patched base class beside an
unpatched versioned copy read as fully patched while Java 9 and later kept
running the old code (#2199).

patch::multi_release finds such copies in a jar for a member-keyed record.
A versioned entry that overrides a member the record changes is fine when
the record lists that path or when its bytes are the patched ones of a
member it overrides; anything else is reported with the member and the
versioned paths. A copy of a member the record does not change is not
looked at.

What a runtime loads is decided as the JDK decides it, from
java.util.jar.JarFile and java.util.zip.ZipFile in OpenJDK 11, 17, 21 and
the current sources, and checked by running OpenJDK 11, 17, 21 and 26:

- the copies count only when the main section of the manifest holds
  Multi-Release: true (name and value in any case, the value with nothing
  after it, on one terminated line); the manifest is found in any case;
- only under exactly META-INF/versions/<n>/ with a plain decimal <n>, and
  never for a name under META-INF/;
- <n> counts from 8, not 9: the specification says 9 and OpenJDK 11
  ignores a directory 8, but OpenJDK 17 and later load it.

The check reads entry names from the central directory, inflates the
manifest only when a candidate copy exists, and hashes only the candidates,
within the existing jar limits. When a candidate exists and the manifest
cannot be read, the copy is reported as one that may be loaded.

Nothing calls the check yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ersioned copy

`vex` attested a Maven patch once every member its record lists hashed to
its afterHash in every jar the build consumes. A multi-release jar that
also holds one of those members under META-INF/versions/<n>/, without the
patch, passed that check while Java <n> and later run the unpatched copy:
the statement said the vulnerable code cannot run where it does (#2199).

The verifier `vex` and `apply --check` share now looks at each such jar
after its members verify: the installed jar of an agent-mode patch, and the
downloaded suffixed jar of a hosted pin. A jar with an unpatched versioned
copy of a patched member omits the package under the reason
`multi_release_unpatched_copy`, and a run warning with the same code names
the jar, the member and the versioned paths. The jar is not listed among
the copies of `vex_gradle_unpatched_copy`, whose warning says to run
`apply`: applying again does not change such a copy.

The member check itself is unchanged. Rollback, variant selection and the
vendored drift probe ask it whether the record's files are in place, and
they are. A record that replaces the jar file whole lists no members, so
nothing is looked for in its jar.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Vendored mode commits the patch service's jar. When that jar is a
multi-release jar that holds a patched member again under
META-INF/versions/<n>/, without the patch, a build on Java <n> or later
still runs the old code, and nothing said so (#2199).

`vendor` (and `scan` / `get` in vendored mode) now reports it the way it
reports a classifier jar with an unpatched copy: the jar is vendored all
the same, with a `vendor_jvm_degraded` warning whose reason is
`multi_release_unpatched_copy` and whose detail names the jar, the member
and the versioned paths. It is said on the first vendoring and on every
in-sync run, for every JVM layout (the check is on the jar, before any
planner runs) and for the jar committed for a Bazel hub. The exit status
stays 0 and nothing is refused: the base member is patched.

`vex` does not attest such an entry. The check is a gate of the plan,
beside the JVM wiring check, so it holds under `--no-verify` as the
classifier one does; the package is omitted under
`multi_release_unpatched_copy` and a run warning names the copy.

The artifact's health check is untouched: the jar holds every file of the
patch, so `vendor --check` passes and `repair` has nothing to rebuild.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… unpatched

Agent mode swaps the patch service's jar in for a record keyed by jar
members, and requires every entry the record does not list to be the
installed jar's own. So a class the record changes that the jar also holds
under META-INF/versions/<n>/ keeps its old bytes there unless the record
lists that copy, and `apply` reported a clean success while Java <n> and
later kept loading the old code (#2199).

After a jar holds the record's members (swapped in by this run, or found
already patched), `apply` now looks for such copies. A jar with one makes
that copy's patch incomplete, under `multi_release_unpatched_copy`: the
same notion `apply` has for a gem whose compiled code is not the patch's.
The jar stays patched, with its backup, and `rollback` restores it; the
copy's event is `failed` under the code and lists what the run wrote, the
human line reads "Patch of <purl> is incomplete: ...", naming the jar, the
class and the versioned paths, the summary counts the package as not in
effect, and the run exits 1. A dry run reports the same, since the swap
leaves the versioned entry as it is on disk. Nothing is undone or refused:
the base class is patched, which is what a Java 8 runtime loads.

`apply --check` words the drift for this reason, names the jar and the
copy, and leaves out its "run apply" remedy when that is the only kind of
drift: applying again does not change such a copy. It takes a patch that
lists the versioned copy.

The incomplete-copy entry now carries its code instead of assuming the
gem one, so both kinds go through the same reporting.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ected

docs/ecosystems.md gets "Other copies of a patched class" under the Maven
caveats, and the CLI contract a section of the same name:

- multi-release jars are checked: what counts as an unpatched versioned
  copy, the JDK rules the check follows (the Multi-Release attribute, the
  exact META-INF/versions/<n>/ spelling, <n> from 8 because JDK 17 and
  later load a directory 8), and what each mode does with the one code
  `multi_release_unpatched_copy`: agent `apply` reports the patch as
  incomplete and exits 1, `apply --check` reports drift, vendored mode
  warns `vendor_jvm_degraded` and exits 0, hosted mode says nothing when
  the pin is written, and `vex` writes no statement in any mode;
- jars nested in a Spring Boot or war archive (BOOT-INF/lib, WEB-INF/lib)
  are not read, reported or patched;
- shaded, relocated or repackaged copies of an artifact's classes are not
  reached or reported.

The contract also lists the code in the general errorCode table, the
`apply --check` row, the agent-mode Gradle table and the VEX table.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A vendored multi-release jar that holds an unpatched versioned copy of a
patched member is reported as degraded, and it still holds every file of
the patch. The vendoring test now also runs `repair` over it and checks
that nothing is rebuilt and no file of the project changes, as it already
checks that `vendor --check` passes: the artifact's health is not what the
warning is about.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The multi-release check listed a jar's names through the reader's name
index, which opens every entry to read its name: the zip reader seeks to
and parses each entry's local header for that. So the check cost a seek and
a read per entry before it looked at anything, on jars of tens of thousands
of entries, and an entry whose local header does not parse was left out of
the names without a trace. A versioned copy in that state made the jar read
as clean instead of as one that could not be checked.

`Jar::member_names` now takes the names from the central directory and
reads no entry. The zip reader keys its entries by the raw bytes of their
names and hands names out decoded; where the decoded name spells those
bytes (ASCII, or flagged UTF-8) its own lookup lands on the same entry,
which shows the raw name without reading anything. Only a name in another
encoding is taken from its entry, and when that entry cannot be read the
jar is reported as not checked.

An entry the directory lists and nothing can read is no longer passed
over: a versioned copy of a patched member in that state, or the manifest
of a jar that holds such a copy, is reported as a copy that could not be
checked. The lookups by name are unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… purl

The plan's gate for a vendored jar with an unpatched versioned copy skipped
the candidate before its key entered the view, and did not record the key
as taken. A later candidate that resolved to the same key (a lockfile-only
one, renamed to the key its record is filed under) was then no collision:
it was planned on its own basis and attested, so one purl carried a
`not_affected` statement beside its `multi_release_unpatched_copy` skip.
Before the gate existed the two collided and neither attested, which is
what the collision branch is for.

The gate now records the key among the collided ones, so the later
candidate is omitted as `record_mismatch`, as it would be had the first
reached the view.

The new test reaches the collision the only way the plan allows today, two
spellings of one NuGet release, with a jar as the vendored artifact.
Discovery canonicalizes purls, so two patches wired to one Maven release
are a wiring conflict before this point; no Maven fixture gets here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…dies as not checked

Two things about where the check ran.

`apply` ran it on the blocking pool and took a task that did not finish (a
panic in the zip reader, a task the runtime dropped) for "no finding", so
it reported the patch applied, while `apply --check` and `vex`, which went
through another helper, re-raised the panic for the same jar. And the
vendored paths did not leave the async worker at all: the `vex` plan parsed
every vendored jar there, and `vendor` did the same over the jar in memory.

One helper in `patch::multi_release` now runs the check on the blocking
pool for every caller: `apply`, the verifier `vex` and `apply --check`
share, the vendored gate of the `vex` plan, and `vendor`. A check that does
not finish comes back as a jar that could not be checked, which each of
them already reports under `multi_release_unpatched_copy`: a jar that is
not checked is not taken for patched, whichever command asks.

`vendor` keeps the jar it handed over: the check borrows the bytes and
gives them back.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…copies

`vendor` and `vex` disagreed about a vendored jar that cannot be checked
at all (it does not open as a jar, or the check did not finish). `vendor`
reported it as degraded, "could not be checked", and the gate of the `vex`
plan passed over it. Verification then refused a jar it could not open,
under its own reason, but `vex --no-verify`, which skips verification,
wrote `not_affected` for it, although the contract says a vendored entry
is not attested there.

The gate now tells the two cases apart. A jar that holds a versioned copy
of a patched member is gated as before. One that could not be checked is
handed on with a note of it, so that verification's own reason
(`vendor_artifact_unreadable`, `vendor_artifact_too_large`) still names
the jar when verification runs; `vex` then omits, under
`multi_release_unpatched_copy`, whichever of those purls still comes out
applied: every one of them under `--no-verify`, and one whose check died
over a jar that verifies. A missing jar stays the wiring checks' and
`vendor_artifact_missing`'s.

The contract says which reason is reported where.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The docs said `vex` writes no statement for a multi-release jar with an
unpatched versioned copy "in any mode". That overstated it for hosted
mode, which never downloads the jar: `vex` reads a hosted pin's jar only
where a build has left it, the suffixed version in the Maven local
repository, a Gradle cache or a hosted sbt build's download directory.

docs/ecosystems.md and the CLI contract now say when the jar is and is not
judged. A hosted pin whose jar no local cache holds is attested from the
pin alone, as every hosted pin is before the project's first build, and
the `--vex` of the hosted `scan` / `get` run that writes or confirms a pin
attests it whatever a cache holds. Neither reads the jar, so neither sees
such a copy. `--no-verify` reads no installed or downloaded jar. This is
the gap hosted pins already have for every other kind of installed
evidence; nothing here downloads a jar to close it.

A test in the hosted Maven VEX suite pins each case: no jar cached
(attested), a cached jar with such a copy (omitted, the warning names it),
the same under `--no-verify` and without `Multi-Release: true` (attested),
and the `--vex` of a hosted scan with that jar cached (attested, while the
standalone `vex` over the same checkout omits it).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ablished

Three loose ends of the last changes.

A vendored jar that is missing was left out of the "could not be checked"
case, on the grounds that verification reports it. So it does, as
`vendor_artifact_missing`, when it runs; under `--no-verify` nothing ran
and `vex` still wrote `not_affected` for an entry with no jar. A missing
jar now takes the same path as one that cannot be opened: verification's
reason stands when it runs, and `--no-verify` omits the entry under
`multi_release_unpatched_copy`.

Every message about a jar that could not be checked said, in its second
half, that the jar holds an unpatched copy and that the patch has to
change it. That is not established for such a jar. The texts now follow
the finding: `apply`, `vendor` and the `vex` warnings say that a jar that
could not be checked is not taken for patched, and keep the advice about
the patch for a copy that is there. The one-line reasons of `vex` and
`apply --check` name both cases.

The docs and the contract named `get --mode hosted` beside the hosted
scan's `--vex`. `get` has no `--vex`; the text is about `scan --mode
hosted`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The previous commit meant a missing vendored jar to be withheld under
`--no-verify`, and its test of that fails: for a JVM tree, the path of the
jar is handed out only once every file of the tree is there, so a missing
jar never reached the check and `vex --no-verify` still wrote
`not_affected`. (The same change did cover a jar outside a JVM tree.)

A JVM tree that lacks one of its files, the jar among them, is now a jar
that was not checked: verification reports `vendor_artifact_missing` when
it runs, as before, and a run that does not verify omits the entry under
`multi_release_unpatched_copy`. The contract says which reason is reported
where, and that a layout whose wiring check reads the tree (Gradle) keeps
reporting `vendor_unwired` either way.

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 17:04
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes JVM patch completeness semantics, VEX attestation, and --no-verify behavior for vendored jars—high user visibility but confined to Maven multi-release member patches.

Overview
Adds detection and reporting when a member-keyed Maven patch is in the base JAR but an unlisted META-INF/versions/<n>/ copy of the same class still holds upstream bytes—so Java 9+ can run vulnerable code while apply/check look “patched.”

A new core module (patch/multi_release) implements JDK-aligned rules (Multi-Release: true, path grammar, version ≥ 8) and scans jars via the central directory with selective hashing. apply runs check_versioned_copies after jar swaps: the patch stays on disk but the run fails with multi_release_unpatched_copy (same incomplete-patch pattern as unrebuilt gem natives); apply --check treats it as drift and drops the generic “run apply” remedy. vendor still commits the jar but emits vendor_jvm_degraded / reason: multi_release_unpatched_copy. vex withholds attestation (vendored plan gate, installed/hosted jar checks when caches are read; --no-verify now omits uncheckable vendored jars instead of attesting). CLI_CONTRACT.md documents the new error code and a new “Other copies of a patched class” section; nested/shaded copies remain explicitly out of scope.

Reviewed by Cursor Bugbot for commit d27c779. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: this needs a product decision before it is ready for approval.

I reviewed the diff at d27c779. CI is green (ci-ok, clippy), there are no open threads, and the 15 multi_release unit tests pass locally. I found no correctness bug in the check: the META-INF/versions/<n>/ parsing, the manifest attribute rules, the listed or identical copy exemptions and the "could not be checked" path all match the description.

What stops me from labelling it is the first item under "For the maintainers to decide". It changes the exit status a user's CI already relies on:

Question: after upgrading, a project with a member-keyed Maven patch for a multi-release jar that has an unlisted versioned copy of a patched class gets exit 1 from agent apply on every run (crates/socket-patch-cli/src/commands/apply.rs, check_versioned_copies), and the user can't clear it until the patch itself is reissued. apply --check drifts too, while vendored mode stays exit 0. Should agent apply fail here, or should it warn and exit 0, the way vendored mode and classifier_unpatched_copy do? If it should fail, does someone first need to count how many published patches this affects (for example log4j-api, h2)?

Second, a smaller behaviour change for the same approver: vex --no-verify no longer writes not_affected for a vendored JVM entry whose jar is missing or can't be opened.

Once a person answers, remove agent:needs-human and I will post the review brief on the next run.


Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added agent:needs-human Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review labels Dec 1, 2026
@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 9f2bc04 Dec 1, 2026
164 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/maven-multi-release-copies branch December 1, 2026 21:29
@Wenxin-Jiang

Copy link
Copy Markdown
Contributor

[agent] Decision from Wenxin Jiang (@Wenxin-Jiang) on the exit-status question: agent apply should warn, not exit 1, when a multi-release jar has an unlisted META-INF/versions/<n>/ copy of a patched class. The same applies when the jar can't be checked. Please change it so agent apply exits 0 with a warning in both cases, and update the tests and CLI_CONTRACT.md to match.

The vex --no-verify question (no not_affected for a missing or unreadable vendored JVM jar) is still open.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants