Repository navigation
Report a multi-release jar's unpatched versioned copy of a patched class (#2199) - #2411
Draft
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Draft
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Mikola Lysenko (mikolalysenko) wants to merge 6 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:apply, member-keyed recordfailedevent with the code,Patch of <purl> is incomplete: …, exit 1. Also on--dry-runand for a jar that was patched earlierapply --checkvendor/scan/getvendor_jvm_degradedwithreason: multi_release_unpatched_copy: …; exit 0, as forclassifier_unpatched_copyvex--no-verifyA 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:Multi-Release: true(name and value in any letter case). Without it they are never read, and nothing is reported.META-INF/versions/<n>/<name>,<n>decimal with no leading zero, and never for a<name>underMETA-INF/.META-INF/versions/8/counts. The JAR specification says8 < nand 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
scan --mode hostedreports nothing.vexchecks the jar once a build has downloaded it. From reading the code (not run), the--vexof the same hosted scan still attests, because that run assumes its own patches are applied.BOOT-INF/lib/,WEB-INF/lib/) and shaded or relocated copies are not detected.docs/ecosystems.mdand the contract now say so.For the maintainers to decide
applyexits 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.Tests
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).tests/gradle_agent_cli.rs(agent apply,--check, dry run) andtests/vendor_jvm_cli.rs(vendored,vendor --check,repair,vex), on offline fixtures.cargo fmt --check,cargo clippy --workspace --all-features -- -D warnings, core lib (8,691 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.docs/ecosystems.mdnameslog4j-apiandh2as multi-release examples, taken from the issue and not checked here.🤖 Generated with Claude Code