Skip to content

Commit 6ea9c11

Browse files
mikolalysenkoclaude
andcommitted
Address review of the re-signed manifest rule
Look a member up by the raw bytes of its name. The zip reader's own lookup is by a name it decodes as CP437 when an entry lacks the UTF-8 flag, so a UTF-8 name written without it was missed and a valid jar refused as holding a section for a member it does not hold. Read the manifest within the jar limits alone: the 16 MiB cap of its own was below them. A jar past a limit while the manifest is read is the caller's too-large refusal, not a difference. Replace the MD5 that computed its constants with f64::sin and held the whole member: a constant table, fed block by block, checked against the RFC 1321 vectors. Take a member's SHA-256 from the digests the comparison already holds instead of inflating it again, open each jar once and parse each section once. Match a changed digest line without regard to the case of its name. Name signing in a refusal only when the patched jar is signed: an unsigned jar whose manifest differs is the ordinary wrong-base case. Remove what no caller reaches: a section dropped with a member the record deletes (every path requires a record member at its afterHash), and the baseline taken from a record that lists the manifest. Such a jar is refused for now, and the contract says so. The docs state the rule as implemented. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 74765d5 commit 6ea9c11

6 files changed

Lines changed: 606 additions & 238 deletions

File tree

‎crates/socket-patch-cli/CLI_CONTRACT.md‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,8 +2831,9 @@ vouches for, else the registry's own download held to the same checksum. Every e
28312831
the JVM would load must hold the same content in both, whatever unix mode it carries;
28322832
the record's members and signature files (`META-INF/*.SF`, `.RSA`, `.DSA`, `.EC`) are
28332833
exempt and directory entries may differ. The manifest of a jar the patch service
2834-
re-signed may differ in the digests of the patched members, by the rule under
2835-
[Agent mode](#agent-mode-apply-scan---mode-agent). A jar that adds, drops or changes anything
2834+
signed again may differ as that signing leaves it (digest lines changed for the
2835+
patched members and added for the others, sections added for entries it did not
2836+
list), by the rule under [Agent mode](#agent-mode-apply-scan---mode-agent). A jar that adds, drops or changes anything
28362837
else is refused with `vendor_prebuilt_integrity_mismatch`, the detail naming up to
28372838
three such members, and a first vendoring commits and wires nothing.
28382839

@@ -3253,11 +3254,13 @@ only as follows; anything else is the refusal above with the reason added:
32533254
4. A section is added only for a member the record adds or changes, or for an entry
32543255
that both jars hold with identical bytes and the installed manifest did not list.
32553256
It holds a `Name` and verified digests alone.
3256-
5. A section is removed only for a member the record deletes.
3257+
5. No section is removed.
32573258

32583259
A digest attribute is one the JDK reads when it verifies a jar: `SHA-256-Digest`,
3259-
`SHA-384-Digest`, `SHA-512-Digest`, `SHA1-Digest`, `SHA-1-Digest`, `MD5-Digest`. An
3260-
added attribute of any other name is a refusal. The manifest is read as the JAR
3260+
`SHA-384-Digest`, `SHA-512-Digest`, `SHA1-Digest`, `SHA-1-Digest`, `MD5-Digest`,
3261+
matched without regard to case. An added or changed attribute of any other name is a
3262+
refusal, the other digests the JDK reads (`SHA-224-Digest`, the SHA-3 ones) among
3263+
them: the service writes none. The manifest is read as the JAR
32613264
specification lays it out (lines end in `\r\n`, `\n` or `\r`, a leading space
32623265
continues a line wrapped at 72 bytes, a blank line ends a section) and its sections
32633266
are compared as the bytes in the file. Blank lines are not compared, so a terminator
@@ -3266,9 +3269,15 @@ manifest with no terminator, which a JVM ignores, may be dropped. The signature
32663269
itself is not verified; that is the JVM's. A rollback finds the original of such a
32673270
copy by the same rule.
32683271

3269-
A record that lists `META-INF/MANIFEST.MF` itself is not covered: the service's
3270-
manifest must then still be the record's after-blob, byte for byte, as for any member
3271-
the record changes.
3272+
A jar whose patch record itself lists `META-INF/MANIFEST.MF` is refused for now when
3273+
the service signed it again. The manifest is then a member the record changes, held
3274+
to its `afterHash`, and the signed manifest is that blob with its digests completed,
3275+
not the blob. Accepting it needs the record's blob wherever a member is held to its
3276+
`afterHash`, and `rollback`, `vex` and the vendored check do not have it at hand.
3277+
3278+
A jar past a limit while its manifest is read is `jvm_jar_too_large` (vendored:
3279+
`vendor_artifact_too_large`), never a mismatch; the manifest has no limit of its own
3280+
below those of the jar.
32723281

32733282
Jars are read within fixed limits, counted on the bytes actually inflated and on the
32743283
archive's own entry count, never on the sizes an archive declares: 200,000 entries

0 commit comments

Comments
 (0)