Skip to content

fix(go): classify JVM class files instead of universal Mach-O for CAFEBABE bytes - #2458

Merged
morluto merged 6 commits into
morluto:mainfrom
Joshwong1908:fix/go-java-class-fat-macho
Oct 13, 2026
Merged

morluto merged 6 commits into
morluto:mainfrom
Joshwong1908:fix/go-java-class-fat-macho

Conversation

@Joshwong1908

@Joshwong1908 Joshwong1908 commented Oct 13, 2026 •

Copy link
Copy Markdown

Summary

inspect-go-binary reports JVM class files (CAFEBABE) as "Universal/fat Mach-O containers require selecting a thin slice" — a false format identity. A JVM class file's bytes 4..7 hold minor_version/major_version, not nfat_arch, so the message steers users to a slice-selection dead end that can never succeed. This is the Go-reader sibling of the disambiguation added for the artifact and target lanes in 921bb95 (fixes #2317); #2405 covers the artifact inventory lane. Contradiction on identical bytes: inspect-artifact already refuses the same class file as unsupported binary format.

Problem and expected behavior

Smallest trigger: rea inspect-go-binary Hello.class (any valid class file; version 65 lands in nfat_arch's plausible 1..128 range).

Violated invariant: docs/go-binaries.md "Supported boundary" — "Unsupported containers receive a separate unsupported-target failure." A class file is not a container of any kind; the unsupported-target reason must not assert a Mach-O FAT identity the bytes do not support.

Expected: the generic Only ELF, PE, and thin Mach-O native images are supported failure, matching the artifact/target lanes.

Change and scope

In src/go/GoBinaryImage.ts readContainer, the four FAT magics now route through the shared readFatContainerHeader + classifyFatContainerIdentity facts. The thin-slice failure is kept only when the container identity is confirmed Mach-O (or the header is truncated/malformed enough that FAT cannot be ruled out, preserving the existing 4-byte behavior). not-fat (class files: table extends past file size) and not-mach-o identities fall through to the generic failure.

Not included: src/hopper/HopperFileOffset.ts fatLayout still classifies CAFEBABE by magic alone; 921bb95's message leaves Hopper readers their own parsing, so I did not change it here.

Contribution scope: focused bug fix within existing boundaries; no new capability, target execution, injection, or mutation. Not applicable for a maintainer scope decision.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Go build-info reader (readGoBinaryImage container admission); earliest stage is target admission for inspect_go_binary.
  • Contribution scope fit and linked maintainer decision: ordinary fix, not applicable.
  • CLI and MCP/tool-catalog contract: unchanged surface; only the unsupported_target reason text for non-Mach-O CAFEBABE inputs changes from the fat-container message to the generic supported-formats message.
  • Provider, bridge, target-format, or platform compatibility: none; pure static classification before any provider is contacted.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata: none; no tool signatures changed (CI-generated catalogs untouched).

Expected effects:

  • 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: tests/boundary/go/goBinaryImage.test.ts — JVM class fixture (both the 57-byte table-overflow form and the 4000-byte parsed-garbage-table form) must hit the generic unsupported failure; confirmed universal containers (repository fatImage/machoImage builders: two real thin Mach-O slices x narrow, FAT64, and both little-endian cigam tables) must keep the thin-slice failure. Commit c39b6a1 lands the failing regression first; e53b21c turns it green; 10328cd and 1b9b658 harden the positive control.
  • Base reproduction: on main @ 37b7550, node scripts/rea.mjs inspect-go-binary Hello.class returns message: "... Universal/fat Mach-O containers require selecting a thin slice"; after the fix it returns "... Only ELF, PE, and thin Mach-O native images are supported".
  • User-visible CLI/MCP output (before → after, executed):
$ rea inspect-go-binary Hello.class            # before (main)
message: "Unsupported target for inspect_go_binary at .../Hello.class: Universal/fat Mach-O containers require selecting a thin slice"

$ rea inspect-go-binary Hello.class            # after (this branch)
message: "Unsupported target for inspect_go_binary at .../Hello.class: Only ELF, PE, and thin Mach-O native images are supported"

$ rea inspect-go-binary fat-real-universal.bin # after (positive control)
message: "... Universal/fat Mach-O containers require selecting a thin slice"
  • Remaining proof gaps: no real macOS-produced universal binary was available on this Linux host; the positive controls are synthesized with the repository's own FAT/Mach-O fixture builders (real thin Mach-O slice headers, all four magics x narrow/wide tables). HopperFileOffset.ts behavior is unchanged and noted above.

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

  • npx vitest run tests/boundary/go/goBinaryImage.test.ts — 81 passed (fails 1/81 on main without the fix)
  • npx vitest run tests/acceptance/artifactInventoryJvmClass.test.ts src/domain/binaryTarget.test.ts tests/boundary/go/ — 141 passed
  • npm run typecheck — clean
  • npm run lint (includes verify:module-boundaries) — 1665 source files checked, clean
  • npm run verify:test-discovery — 1003 test files discovered exactly once
  • npm run build:cached then both CLI invocations above — executed, output quoted
  • Full-repo vitest lanes (src-unit 5490 tests, boundary+process+mcp 4102, cli-boundary 314, acceptance 290, test:python 9) — all green; every observed failure reproduced verbatim on a pristine main checkout (pre-existing) or was environmental/load-flaky passing on rerun
  • Adversarial sweep of 151 crafted inputs (all FAT magics x truncation/count/offset/endian boundaries, double-magic, 50 seeded-random buffers) via the built CLI — zero invariant violations, only the two documented message buckets

Compatibility, safety, and release

  • Breaking changes or migration steps: none; an error message for non-Mach-O CAFEBABE inputs becomes accurate.
  • Real Hopper/Ghidra, browser, or OS coverage: not needed (pure static classification); verified on Linux x64 via CLI.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: not applicable (read-only classification).

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 (family context: [Bug] Artifact inventory labels JVM class files as universal Mach-O executables #2317; sibling lane: fix(artifacts): classify JVM class files instead of universal Mach-O for CAFEBABE bytes #2405; no Go-lane issue exists).
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed (no doc change required: behavior now matches the documented boundary).
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

The regression fails on main: readGoBinaryImage(javaClassFile()) reports
"Universal/fat Mach-O containers require selecting a thin slice" for a
JVM class file whose bytes 4..7 are minor/major version, not nfat_arch.
Route the four FAT magics through the shared readFatContainerHeader and
classifyFatContainerIdentity facts added for the same disambiguation in
the artifact and target lanes (921bb95). Keep the thin-slice failure
only when the container identity is confirmed Mach-O; a JVM class file
now falls through to the generic only-ELF/PE/thin-Mach-O failure.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@Joshwong1908
Joshwong1908 marked this pull request as draft October 13, 2026 03:08
Cover the kept behavior with the repository's own fatImage/machoImage
builders (narrow and FAT64 tables) so the regression also proves real
universal containers keep the slice-selection failure.
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Refines binary format detection for JVM class files.

The truncated-header error contract still needs to be restored before merging.

Findings

  1. P1 Existing Go test fails ▶
Fix with agent prompt
### Issue 1
src/go/GoBinaryImage.ts:undefined-208
`confirmedFatMachO` now sends the four-byte `CAFEBABE` input to the generic supported-formats error. The existing test in `goBinaryImage.test.ts` still expects `/universal|fat/i`, so that assertion now fails. This also drops the truncated-header behavior promised in the PR description.

Preserve that behavior separately from parsed malformed tables, or update the test and stated contract if the message change is intentional.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR uses shared FAT-header checks to distinguish JVM class files from universal Mach-O containers.

  • Go binary inspection no longer labels JVM class files as universal Mach-O.

Reviews (4) · Last reviewed commit: "fix(go): retain malformed FAT header dia..." · Reviewed by Greptile

Comment thread src/go/GoBinaryImage.ts Resolved
@morluto
morluto marked this pull request as ready for review October 13, 2026 11:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T12:25:21.707424Z 1a14c05 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Require positive Mach-O identity before reporting a universal thin-slice remedy; malformed FAT-shaped bytes are not proof. Add the JVM constant-pool CPU lookalike to the existing fixture control.

Source inspection and git diff --check; tests/builds/typechecks/CI reruns skipped at explicit user request.
Comment thread src/go/GoBinaryImage.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a14c05efa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/go/GoBinaryImage.ts Resolved
Preserve the owning FAT header parser reason for malformed headers while requiring positive Mach-O proof before the universal-slice remedy.

Source inspection and git diff --check only. Tests, builds and typechecks skipped by explicit user request. GitHub review writes paused globally.
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1, thread 2

Fixed in 617a4b4.

Root cause and structural fix: Malformed FAT headers preserve the owning parser reason, including the truncated-header diagnostic. Parsed malformed tables still do not establish Mach-O identity, so the JVM CPU-lookalike remains free of a false thin-slice remedy.

Validation: source inspection and git diff --check only. Tests, builds and typechecks were skipped by the user's explicit request; no runtime or real-provider pass is claimed. No directly related cleanup remains identified.

@morluto
morluto merged commit 48b92e1 into morluto:main Oct 13, 2026
4 checks passed
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Artifact inventory labels JVM class files as universal Mach-O executables

2 participants