[PR #3305] [CLOSED] fix(apple): stop JVM class lookalikes passing as FAT Mach-O #5715

Closed
opened 2026-10-31 01:08:52 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3305
Author: @Sriram-PR
Created: 10/14/2026
Status: ❌ Closed

Base: main ← Head: fix/fat-jvm-class-lookalike


📝 Commits (2)

  • a8e2a55 fix(apple): stop JVM class lookalikes passing as FAT Mach-O
  • d6b1041 test(apple): pin the binary target refusal for JVM FAT lookalikes

📊 Changes

3 files changed (+53 additions, -4 deletions)

View changed files

📝 src/artifacts/apple/MachoLoadCommandReader.test.ts (+38 -2)
📝 src/domain/apple/machoContainer.ts (+7 -2)
📝 src/domain/binaryTarget.test.ts (+8 -0)

📄 Description

Summary

trace-dylib-resolution with automatic root discovery reported a valid JVM class resource as a malformed Mach-O when its constant pool happened to contain a known Mach-O CPU value. The class landed in coverage.unparsed_images and coverage dropped to partial. classifyFatContainerIdentity treated any known CPU type in the FAT-shaped table as proof of Mach-O, then reported the slice range as malformed without ever confirming a slice header.

Fixes #3176

Problem and expected behavior

Smallest trigger: a class file (0xCAFEBABE, major version 65 read as 65 FAT records) whose constant pool puts 0x00000007 (x86) in a CPU-type slot, with a declared slice offset past the end of the file. This is the javaClassFile(4000, true) fixture the Go reader already tests against. Expected: not-mach-o, so the class stays out of the image list and coverage stays complete.

Change and scope

  • In src/domain/apple/machoContainer.ts, a known CPU type now counts as Mach-O identity only for a slice that starts inside the file. The parsed FAT header carries fileSize so the identity check can tell.
  • Real FAT containers whose slice starts inside the file but is truncated, misaligned, or uses an unsupported alignment are still reported as malformed/unsupported exactly as before (the existing reader tests for those cases pass unchanged).
  • Other identity consumers: the artifact graph format and the Go reader only act on a confirmed mach-o identity, so they are unchanged for these inputs. binaryTarget still rejects the file, but its reason changes from FAT architecture N slice range extends beyond the file to FAT table does not identify a Mach-O image.
  • Trade-off, stated plainly: a FAT file truncated before any slice begins, with no other evidence, is now not-mach-o instead of malformed. Its bytes can't be told apart from the JVM lookalike, and no existing test covers that case. Unknown-CPU tables were already classified this way.

Contribution scope: ordinary fix within existing boundaries; no scope decision needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: classifyFatContainerIdentity in src/domain/apple/machoContainer.ts, the shared FAT identity decision.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix, #3176).
  • CLI and MCP/tool-catalog contract: no schema change.
  • Provider, bridge, target-format, or platform compatibility: FAT-magic files whose known-CPU slices all start past the end of the file are classified not-mach-o instead of malformed; see trade-off above.
  • Evidence, artifact, provenance, or reconstruction contract: dylib traces no longer list such class files as images or unparsed images, so coverage is complete when nothing else is missing.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated (src/artifacts/apple/MachoLoadCommandReader.test.ts):
    • the existing JVM case now also reads javaClassFile(4000, true) and expects not-mach-o;
    • a new dylib trace test enumerates an app bundle containing a Mach-O executable plus a lookalike and a plain class resource, and expects only the executable in images with complete coverage.
  • Base reproduction: both fail on the base revision (malformed instead of not-mach-o; trace images include Contents/Resources/Look.class).
  • An earlier attempt that ignored known CPUs on any invalid-range slice broke the existing truncated/unaligned/alignment-exponent FAT tests, which is why the rule is limited to slices starting past the end of the file.
  • User-visible CLI output: an Example.app with a thin arm64 Mach-O executable plus the two class resources:
    base: images ["Contents/MacOS/Example", "Contents/Resources/Look.class"]
          coverage {"status":"partial","unparsed_images":["Contents/Resources/Look.class"]}
    PR:   images ["Contents/MacOS/Example"]
          coverage {"status":"complete","unparsed_images":[]}
    
  • Remaining proof gaps: ran on Linux x64 only; no Hopper or other engine involved.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/artifacts/apple/MachoLoadCommandReader.test.ts — 28 passed (both new assertions fail on the base revision)
  • npm run test:local -- src/domain/binaryTarget.test.ts — 37 passed (new JVM lookalike refusal-reason test fails on the base revision)
  • npm run test:focused on the 42 test files that use FAT/universal fixtures, javaClassFile or the FAT container helpers (Mach-O, dylib, artifact inventory, binary target, Go, Hopper, Ghidra) — 41 passed, 1 skipped; 836 tests passed, 9 skipped
  • npm run check:fast — typecheck and lint passed
  • CLI comparison above, built with npm run build:cached on base and on this branch

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; Linux x64, Node 24.18.0.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; header classification only, no target execution.

Author readiness

Human owner: @Sriram-PR

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/3305 **Author:** [@Sriram-PR](https://github.com/Sriram-PR) **Created:** 10/14/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/fat-jvm-class-lookalike` --- ### 📝 Commits (2) - [`a8e2a55`](https://github.com/morluto/rea/commit/a8e2a55c29c16e87b13a94bdcc4c9af9abf45fbc) fix(apple): stop JVM class lookalikes passing as FAT Mach-O - [`d6b1041`](https://github.com/morluto/rea/commit/d6b1041d70bf1c7997d86a812ae6b712737a54e2) test(apple): pin the binary target refusal for JVM FAT lookalikes ### 📊 Changes **3 files changed** (+53 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/artifacts/apple/MachoLoadCommandReader.test.ts` (+38 -2) 📝 `src/domain/apple/machoContainer.ts` (+7 -2) 📝 `src/domain/binaryTarget.test.ts` (+8 -0) </details> ### 📄 Description ## Summary `trace-dylib-resolution` with automatic root discovery reported a valid JVM class resource as a malformed Mach-O when its constant pool happened to contain a known Mach-O CPU value. The class landed in `coverage.unparsed_images` and coverage dropped to `partial`. `classifyFatContainerIdentity` treated any known CPU type in the FAT-shaped table as proof of Mach-O, then reported the slice range as malformed without ever confirming a slice header. Fixes #3176 ## Problem and expected behavior Smallest trigger: a class file (`0xCAFEBABE`, major version 65 read as 65 FAT records) whose constant pool puts `0x00000007` (x86) in a CPU-type slot, with a declared slice offset past the end of the file. This is the `javaClassFile(4000, true)` fixture the Go reader already tests against. Expected: `not-mach-o`, so the class stays out of the image list and coverage stays complete. ## Change and scope - In `src/domain/apple/machoContainer.ts`, a known CPU type now counts as Mach-O identity only for a slice that starts inside the file. The parsed FAT header carries `fileSize` so the identity check can tell. - Real FAT containers whose slice starts inside the file but is truncated, misaligned, or uses an unsupported alignment are still reported as `malformed`/`unsupported` exactly as before (the existing reader tests for those cases pass unchanged). - Other identity consumers: the artifact graph format and the Go reader only act on a confirmed `mach-o` identity, so they are unchanged for these inputs. `binaryTarget` still rejects the file, but its reason changes from `FAT architecture N slice range extends beyond the file` to `FAT table does not identify a Mach-O image`. - Trade-off, stated plainly: a FAT file truncated before *any* slice begins, with no other evidence, is now `not-mach-o` instead of `malformed`. Its bytes can't be told apart from the JVM lookalike, and no existing test covers that case. Unknown-CPU tables were already classified this way. Contribution scope: ordinary fix within existing boundaries; no scope decision needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: `classifyFatContainerIdentity` in `src/domain/apple/machoContainer.ts`, the shared FAT identity decision. - Contribution scope fit and linked maintainer decision: not applicable (bug fix, #3176). - CLI and MCP/tool-catalog contract: no schema change. - Provider, bridge, target-format, or platform compatibility: FAT-magic files whose known-CPU slices all start past the end of the file are classified `not-mach-o` instead of `malformed`; see trade-off above. - Evidence, artifact, provenance, or reconstruction contract: dylib traces no longer list such class files as images or unparsed images, so coverage is `complete` when nothing else is missing. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated (`src/artifacts/apple/MachoLoadCommandReader.test.ts`): - the existing JVM case now also reads `javaClassFile(4000, true)` and expects `not-mach-o`; - a new dylib trace test enumerates an app bundle containing a Mach-O executable plus a lookalike and a plain class resource, and expects only the executable in `images` with `complete` coverage. - Base reproduction: both fail on the base revision (`malformed` instead of `not-mach-o`; trace images include `Contents/Resources/Look.class`). - An earlier attempt that ignored known CPUs on any invalid-range slice broke the existing truncated/unaligned/alignment-exponent FAT tests, which is why the rule is limited to slices starting past the end of the file. - User-visible CLI output: an `Example.app` with a thin arm64 Mach-O executable plus the two class resources: ``` base: images ["Contents/MacOS/Example", "Contents/Resources/Look.class"] coverage {"status":"partial","unparsed_images":["Contents/Resources/Look.class"]} PR: images ["Contents/MacOS/Example"] coverage {"status":"complete","unparsed_images":[]} ``` - Remaining proof gaps: ran on Linux x64 only; no Hopper or other engine involved. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npm run test:local -- src/artifacts/apple/MachoLoadCommandReader.test.ts` — 28 passed (both new assertions fail on the base revision) - `npm run test:local -- src/domain/binaryTarget.test.ts` — 37 passed (new JVM lookalike refusal-reason test fails on the base revision) - `npm run test:focused` on the 42 test files that use FAT/universal fixtures, `javaClassFile` or the FAT container helpers (Mach-O, dylib, artifact inventory, binary target, Go, Hopper, Ghidra) — 41 passed, 1 skipped; 836 tests passed, 9 skipped - `npm run check:fast` — typecheck and lint passed - CLI comparison above, built with `npm run build:cached` on base and on this branch ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: not applicable; Linux x64, Node 24.18.0. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none; header classification only, no target execution. ## Author readiness Human owner: @Sriram-PR - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:08:52 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5715
No description provided.