Repository navigation
Read jars within jar-sized limits and compare patched jars member by member - #2132
Conversation
…ream Agent mode and vendored mode read jars through the zip reader written for Python wheels: 10,000 entries and 64 MiB inflated at most, regular-file entries only, both jars held whole in memory. Released jars are past those caps (hive-exec-3.1.3: 23,728 entries, 93 MiB), so agent mode refused them as "the patch service's jar is unreadable", and a vendored one could not be attested, re-vendored online or repaired. Jars now have their own reader (patch/jar_members): member by member, hashing as it inflates, bounded by what is actually inflated and by the archive's own entry count rather than by declared sizes. The limits are 200,000 entries, and per pass 1 GiB inflated and 100 times the jar's size (64 MiB for a small jar). A jar past one is jvm_jar_too_large (agent) or vendor_artifact_too_large (vendored), and the message names the limit. The comparison of a patched jar with the original covers every entry the JVM would load, whatever unix mode it carries: an entry with a symlink's mode bits was skipped, so a class added that way went unseen. Directory entries and signature files stay exempt. A first vendoring makes that comparison too, against the registry-verified upstream jar and before anything is written. It used to run only on an online re-run over a committed tree, so a service jar built from another base was committed and wired. A copy that differs outside the patch now fails with jvm_agent_service_jar_mismatch, naming the members; the per-copy error carried no code. A ~/.m2 jar that another project (or an earlier workspace over a cached repository) patched has no backup in this project. Its rollback now restores the registry's jar when the download matches the registry's checksum and is the jar the copy was patched from, and otherwise says what happened and how to recover, as does an apply over a copy that holds another revision of the patch. -Dmaven.repo.local in the project's .mvn/maven.config names the local repository, between the command line (MAVEN_ARGS) and MAVEN_OPTS, as in Maven 3.6.3, 3.8.9, 3.9.16 and 4.0.0-rc-7. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Read `.mvn/maven.config` only for a Maven build, and as its Maven reads it. A Gradle or Scala-tool build's mavenLocal() never reads the file, so such a project keeps the environment's repository. Maven before 3.9 splits the file on whitespace and interpolates nothing; 3.9 and later take a line as one argument. The Maven Wrapper says which applies; without one the reading whose directory exists is used, and when both exist no repository is guessed at (maven_local_repository_undetermined). An empty value and an undefined placeholder resolve as Maven resolves them, instead of falling through to the settings. A first vendoring no longer fails when the registry cannot be reached while the patch service can. The baseline is the registry-verified jar, else the local repository's jar, else none; the last two are reported (vendor_jvm_upstream_unverified). A mismatch is still a refusal. A rollback reads the copy before it looks for a backup or downloads anything: a `~/.m2` copy past the jar limits fails as that, not as a missing backup, and a Gradle copy's backup is found by its hash directory without reading the copy. The copy is hashed once. The central directory is bounded by what the archive's end records declare, before the zip reader parses it: 200,000 entries, 64 MiB. Also: the Gradle classifier check fails closed on a jar it cannot read; `vendor --check` names the limit a jar is past; the digest passes run on the blocking pool and identical copies are read once; a copy's refusal code travels beside its result instead of being parsed out of the text. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryHigh Risk Overview Agent jar swaps compare service vs installed jars member-by-member (including symlink-mode entries), emit coded per-copy Project runs resolve the Maven local repository via Reviewed by Cursor Bugbot for commit c500e5a. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c500e5a. Configure here.
apply_jar_swap and rollback_jar_swap verified a copy's patched members through the zip reader directly, before the bounded reader saw the jar: the central directory was parsed, and allocated for, whatever the end records declared, and a member was inflated with no budget. A copy past the limits, or one with a hostile end record, could exhaust memory there instead of failing as jvm_jar_too_large, and a ~/.m2 rollback could go on to the registry afterwards. The member check now goes through the bounded reader, so the limits on the entry count and the central directory are held to the end records before anything parses the directory, and members are inflated within the pass's budget. A copy past a limit is refused there: jvm_jar_too_large on apply, with the run warning, and on rollback, before any backup is read or anything is downloaded. The unbounded member hasher has no caller left and is removed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: final review found one defect and two owner questions, so this PR is not ready to approve yet. CI is green on 1. Trailing bytes bypass the pre-parse limit check (crates/socket-patch-core/src/patch/jar_members.rs:262)
A probe showed the gap. A 200,001-entry zip gives The Possible fix: check every 2. Owner question: first vendoring without a registry-verified upstream (crates/socket-patch-core/src/vendor/maven_repo.rs:1076) When the registry can't be reached, the baseline falls back to an unverified local-repository jar, or to no comparison at all. The tree is still committed and wired, with only a 3. Owner question: This is already listed in the description. A cloned project's I removed Generated by Claude Code |
The check before the parse read the last 64 KiB of the file and the 56 bytes at the zip64 locator's offset. The zip reader does not take the end record from there: it looks for one backwards through the whole file, finds a zip64 record forwards from where the locator points, and falls back to an earlier end record when a directory does not parse. With bytes appended after the end record, an archive of 200,001 entries passed the check and was parsed whole before the count refused it. The check now walks as the reader does. It finds the last end record the reader can take and holds it to the limits. The reader is then shown zeros below that record's central directory while it opens the archive, so the only records it can fall back to are in the directory itself, and each of those is held to the limits as well. A record the reader would pass over is passed over; after 64 of them the archive is given up, since each costs a search of the file. An end record in a member's data, as a jar stored inside a fat jar has, is below the outer directory: the reader cannot take it, so it is not looked at, whatever it declares. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] Item 1 ("Trailing bytes bypass the pre-parse limit check") is fixed in a4079df. The check before the parse now walks end records the way the zip reader does: backwards from the end of the file whatever follows the record, with the zip64 record found forwards from where the locator points. It holds the first record the reader can take to the limits, and the reader is shown zeros below that record's central directory while it opens the archive, so the only records it can fall back to are inside the directory itself; those are held to the limits too. A nested jar's end records sit in member data below the outer directory, so the reader cannot take them and a fat jar is not refused for them. Tests: Items 2 and 3 await the owner. Labels are unchanged. |
Vendoring a Maven or Gradle patch downloaded the original jar from the registry to compare the patch service's jar with, and refused or warned when it could not. It does not need the registry for that: the service's jar is checked as it was served (transfer integrity, the record's members at their afterHash) and committed. One comparison stays, since it costs no network and protects the build. When the original jar is already in the build's local repository, the members the patch does not touch must be that jar's, as agent mode requires before a swap. A difference means the project builds with a jar that is not the one the patch was made from, and the refusal says so. With no local copy nothing is compared and nothing is said. An online re-run over a committed tree makes the same local comparison and no longer needs the registry for the jar. Upstream metadata (pom, parents, module metadata, classifier jars) is read as before. Document that a project's .mvn/maven.config chooses where apply, rollback and remove write, what they do there, and that MAVEN_REPO_LOCAL takes the choice back. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] The owner answered items 2 and 3; both are in 855ad75. Item 2 (first vendoring when the registry cannot be reached). The owner's decision: vendored mode does not download a jar from the upstream registry to compare it, and vendoring succeeds with the patch service and the local machine alone. The registry download of the original jar is removed, with the refusal and the Item 3 ( The PR title and description are updated. Labels are unchanged. |
…d-checks main moved wrapper_maven_version into formats::maven::declared_maven and added shared answers to which Maven a project declares and how a maven.config line is read. The local repository lookup now uses them: DeclaredMaven (the wrapper's release, or a root pom only Maven 4 reads) decides how .mvn/maven.config is read, maven_config_line_properties is the reading for Maven 3.9 and later, and RootDirectory says which root directory property the declared Maven fills in. The whitespace reading of Maven before 3.9 and the choice between the two readings stay here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
[agent] PR shepherd: review brief for the approver What it does. Maven and Gradle jars get a reader of their own ( Risk: high. It changes the core JVM apply, rollback and vendor checks. A wrong limit or comparison could refuse a jar that works today, or turn a user's Look here
Verified
Changes I made: none. Open questions: none blocking. Reading upstream metadata (poms, module metadata) without the registry is left for a follow-up, as the description says. Generated by Claude Code |
The base PR (#2132) was squash-merged into main, so the branch's copy of its commits conflicted with the squash. Resolved by a three-way merge over the base PR's last head, so the result carries main plus exactly this PR's own changes. Assisted-by: Claude Code:claude-opus-5-5

Fixes six jar-handling defects in agent and vendored mode for Maven and Gradle packages: jars are read within limits of their own, and a patched jar is compared member by member with the jar the build already has. Vendoring needs no upstream registry for the jar.
What was wrong, and what changes
1. Large jars could not be patched. Jars were read through the zip reader written for Python wheels: at most 10,000 entries and 64 MiB inflated, with both jars held whole in memory.
hive-exec-3.1.3.jarhas 23,728 entries and inflates to 93 MiB;poi-ooxml-full-5.2.5.jarhas 15,181 entries. Agent mode refused such a jar asjvm_agent_service_jar_mismatch: the patch service's jar is unreadable. In vendored modevexomitted it (vendor_artifact_unreadable), an online re-run was refused (vendor_prebuilt_integrity_mismatch) andrepairfailed, where the strict reader also refused non-ASCII names anda.classbesideA.class.Jars now have their own reader (
patch/jar_members.rs). It goes member by member and hashes as it inflates, so memory holds one digest per member, not the members. The limits are counted on bytes actually inflated and on the archive's own entry count, never on declared sizes:A jar past a limit gets its own code and a message that names the limit:
jvm_jar_too_largein agent mode,vendor_artifact_too_largein vendored mode. The Gradle classifier check used the same capped reader and passed a large jar unchecked; it now reads the patched members within the limits.2. A first vendoring never compared untouched members with the original. A comparison ran only on an online re-run over a committed tree, and it needed the upstream jar from the registry. A first vendoring now makes the one comparison that costs no network: when the original jar is already in the build's local repository, the members the patch does not touch must be that jar's, as agent mode requires before a swap (
vendor_prebuilt_integrity_mismatch, naming up to three members, nothing written). A difference means the project builds with a jar that is not the one the patch was made from. With no local copy the service's jar is committed as served, and nothing is said. No copy of the original is downloaded, on a first vendoring or on a re-run.3. Entries the comparison skipped. Entries that are not regular files were skipped, which includes one carrying a symlink's mode bits. The JVM ignores unix mode and loads it as a class. The comparison now covers every entry the JVM would load. Directory entries may differ and
META-INF/*.{SF,RSA,DSA,EC}stay exempt.4.
-Dmaven.repo.localin.mvn/maven.configwas not read. It is now, for a project that is a Maven build (apom.xml, and no Gradle or Scala-tool build beside it: theirmavenLocal()never reads the file), in Maven's order:MAVEN_REPO_LOCAL,MAVEN_ARGS,.mvn/maven.config,MAVEN_OPTS, settings,~/.m2/repository. The file is read as the project's Maven reads it, which I checked against Maven 3.6.3, 3.8.9, 3.9.16 and 4.0.0-rc-7: before 3.9 the whole file is split on whitespace and nothing is interpolated; from 3.9 a line is one argument, so a value runs to the end of its line. On all four the config beatsMAVEN_OPTS, the last occurrence wins, an empty value is the directory Maven runs in, and an undefined placeholder stays in the path. The Maven Wrapper says which reading applies. Without one, the reading whose directory exists is used; when both exist nothing is guessed (maven_local_repository_undetermined).5. A refusal with no code. A copy that differs from the service's jar outside the patch failed with plain text. Its error now starts with
jvm_agent_service_jar_mismatch:and names the members, and the run carries the code as a warning.6. Reversibility tied to one project's
.socket/. A~/.m2copy that is already patched gets no backup, so a second project, or a new workspace over a cached~/.m2, could not roll it back.rollbackandremovenow download the original from the registry and use it only when it matches the registry's checksum (.sha512, else.sha1) and is the jar the copy was patched from: the record's members at theirbeforeHash, every other member the copy's own. The.sha1Maven wrote beside the jar cannot be used, because the swap rewrites it for the patched jar. When no such copy can be had,jvm_jar_backup_missingsays which check failed and how to recover. Anapplyover a copy that holds another revision of the patch says the same.Reason codes and exit status
apply, jar over the old capsjvm_agent_service_jar_mismatchapply, jar over the new limitsjvm_agent_service_jar_mismatchjvm_jar_too_large(new)apply, one copy differs outside the patchjvm_agent_service_jar_mismatchon the event and as a run warningapply, service jar adds a class in a non-regular entryjvm_agent_service_jar_mismatchrollback/remove,~/.m2jar with no backup here, onlinejvm_jar_backup_missingvendor_prebuilt_integrity_mismatch, nothing writtenvex,vendor --check, online re-run,repairon a vendored jar over the old capsvendor_artifact_unreadablevendor_artifact_too_large(new);repairrestores the recorded jarvendor_jvm_upstream_unavailablerollbackof a~/.m2copy past the jar limitsjvm_jar_backup_missingjvm_jar_too_large; nothing downloadedmaven.configreads two ways, both directories present, no wrapper~/.m2patched,maven_local_repository_undetermined(new)CLI_CONTRACT.md,docs/ecosystems.mdanddocs/design/maven-vendoring.mddescribe the codes, the limits, the upstream restore and the.mvn/maven.configlookup.Review (
/code-review high), second commitAll ten findings were confirmed and fixed.
~/.m2copy past the limits fails asjvm_jar_too_largewith nothing downloaded; a Gradle copy's backup is found by its hash directory without reading the copy.classifier_unpatched_copy).vendor --checkmessage. Names the limit the jar is past.apply_jar_swapreturns the refusal beside each copy's result.Owner decisions
Vendoring does not ask the registry for the jar. The owner's rule: vendored mode never downloads a jar from the upstream registry in order to compare it, and vendoring a Maven or Gradle patch succeeds with the patch service and the local machine alone. So the registry download of the original jar is gone, with the refusal and the warning that came with it, on a first vendoring and on an online re-run (which on
mainrefused withvendor_jvm_upstream_unavailablewhen it could not get the jar). The comparison with a jar already in the local repository stays.vendor_jvm_upstream_unverifiedkeeps its meaning for upstream metadata and is no longer raised for the jar.What still reads the registry: upstream metadata. The pom of the patched artifact, its parent poms, Gradle module metadata, classifier and sources jars and their checksums are read from the local caches and otherwise from the registry, as on
main. An online re-run with no local pom still refuses when the registry cannot be reached. That is a follow-up, not part of this PR..mvn/maven.configmay choose where agent mode writes. Accepted as consistent with Maven, and documented indocs/ecosystems.mdbeside the local-repository lookup and inCLI_CONTRACT.mdunder agent mode: what the config can pointapply,rollbackandremoveat, what socket-patch does there, and thatMAVEN_REPO_LOCALtakes the choice back. No new warning.Test:
a_first_vendoring_compares_with_the_local_jar_and_asks_the_registry_for_none(registry unreachable and no local copy commits with no warning; a matching local copy commits; a differing one refuses and names the members; no jar is requested from the registry; an online re-run over the committed tree succeeds).Later fixes
The member check ran before the bounded reader.
apply_jar_swapandrollback_jar_swapverified a copy's patched members through the zip reader directly, so the limits were applied only after an unbounded parse. The member check now goes through the bounded reader: a copy past a limit fails asjvm_jar_too_largeat its first parse, and a rollback stops there without reading a backup or reaching the registry (a_copy_past_the_limits_is_refused_before_it_is_parsed).End records anywhere in the file. The check before the parse read only the last 64 KiB of the file. The zip reader looks for an end record backwards through the whole file, finds a zip64 record forwards from where the locator points, and falls back to an earlier end record when a directory does not parse. With bytes appended after the end record, an archive of 200,001 entries passed the check and was parsed whole before the count refused it.
The check now walks as the reader does. It finds the last end record the reader can take, wherever it sits, and holds it to the limits. Then the reader is shown zeros below that record's central directory while it opens the archive, so the only records it can fall back to are inside the directory itself, and each of those is held to the limits as well. A record the reader would pass over is passed over; after 64 of them the archive is given up as unreadable, since each costs a search of the file.
This is also how a fat jar is handled. A jar stored inside another has its own end records, in the outer jar's member data. That is below the outer directory, so the reader cannot take them and they are not looked at: the outer directory is what counts, whatever a nested jar declares. Checking every end record in the file instead would have refused a fat jar for a nested jar's record that the reader never reaches.
Tests:
the_central_directory_is_bounded_before_it_is_parsed(appended bytes, a zip64 record found forwards from an early locator offset, records that lead nowhere),an_archive_past_the_limit_is_refused_unparsed_with_bytes_after_it(a real 200,001-entry archive with 70,000 bytes appended),a_fat_jar_with_a_stored_nested_jar_is_accepted(a stored nested jar within the limits and one past them).origin/mainhad nothing to merge: the branch was already rebased onto the commit that holds #2100 and #2118, so there is no merge commit and no force-push.Tests
Each fix has a test that fails without it.
patch::jar_members(limits, the central directory bounded before it is parsed, mode-bit entry),patch::jvm_jar(large-jar swap and rollback, coded refusal,~/.m2upstream restore, a rollback that checks the copy first),vendor::maven_repo(large jar through vendoring, verify, re-run and repair; first vendoring refused for a changed, added, mode-bit and missing member; the baseline order without the registry),vendor::jvm::gradle(unreadable classifier jar),crawlers::maven_crawler(precedence, Gradle builds, per-version tokenisation, values as Maven uses them).gradle_agent_cli,vendor_jvm_cli,maven_sidecar_cli(the config's repository is the one patched; an ambiguous config patches nothing and says so; a second project rolls a shared jar back from verified upstream).e2e_vendor_maven_build::maven_config_local_repository_is_the_one_maven_and_socket_patch_use.Results on macOS (arm64) at
2caee0127, which mergesmain:cargo test -p socket-patch-core --tests: 8,692 tests pass.cargo test -p socket-patch-cliforgradle_agent_cli,vendor_jvm_cli,maven_sidecar_cli,contract_gradle_codes: 89 pass.--ignored:e2e_vendor_maven_build, 6 pass.--ignored maven_), against the live patch service and Maven Central: hosted, vendored and agent pass, on Java 26 only.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --all -- --check: clean.cargo check --all-targets, the rest of the CLI suite, and anything on Linux or Windows.The merge of
mainalso moved the local-repository lookup onto the helpersmainnow shares: which Maven a project declares (its wrapper's release, or a root pom only Maven 4 reads), the reading of amaven.configline on Maven 3.9 and later (so--defineand quoted arguments are read too), and which root-directory property that Maven fills in. The whitespace reading of Maven before 3.9, and the choice between the two readings when the project declares no Maven, stay in the lookup.For the owner
MAVEN_ARGSwhatever Maven is installed; Maven before 3.9 ignores it. That was already so and is now documented.SOCKET_MAVEN_REGISTRY).--offlinekeeps it local.Generated by Claude Code