[PR #2329] [CLOSED] fix(inventory): stop labeling JVM class files as universal Mach-O #5166

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2329
Author: @sx4im
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: fix/2317-class-file-mislabel


📝 Commits (1)

  • 0f7d3f7 fix(inventory): stop labeling JVM class files as universal Mach-O

📊 Changes

2 files changed (+71 additions, -1 deletions)

View changed files

➕ src/artifacts/inventory/ArtifactGraphConstruction.test.ts (+58 -0)
📝 src/artifacts/inventory/ArtifactGraphConstruction.ts (+13 -1)

📄 Description

Summary

Fixes #2317.

classifyArtifactBytes in src/artifacts/inventory/ArtifactGraphConstruction.ts returned "mach-o-universal" for every prefix starting with CA FE BA BE. JVM class files share that magic with FAT Mach-O headers, so inspect-artifact on a JAR or ZIP reported each .class entry as artifact_kind: executable, artifact_format: mach-o-universal, the same labels a real universal binary in the same archive gets.

Problem and expected behavior

Bytes 4-7 of a class file are the class-file minor_version/major_version, not the FAT nfat_arch. The issue asks for a non-Mach-O format and no executable kind. This change classifies class files as file, so the occurrence kind falls back to the path role (resource for .class paths) instead of executable.

Change and scope

  • classifyArtifactBytes now checks, for the big-endian 0xcafebabe magic only, whether bytes 6-7 hold a plausible class-file major version (>= 45, the first version real compilers emit). If so it returns "file". The byte-swapped FAT magics are untouched: class-file bytes are always big-endian per the JVM spec.
  • Added src/artifacts/inventory/ArtifactGraphConstruction.test.ts with 4 tests.
  • Left out: a dedicated java-class format. That would extend the artifact format schema and touch every consumer switch; the issue explicitly accepts file.

Follow the contribution scope. Routine bug fix inside existing boundaries; no new provider or capability, so no maintainer scope decision is needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: artifact inventory byte classification (classifyArtifactBytes), consumed by classifyArtifactContent and the ZIP scan reader.
  • Contribution scope fit and linked maintainer decision: routine fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: class-file occurrences now report artifact_format: file (kind resource for .class paths) instead of the unsupported Mach-O labels. Real FAT binaries keep their labels.

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/inventory/ArtifactGraphConstruction.test.ts (4 tests).
  • Base reproduction or other evidence: TDD. The two class-file tests failed before the fix (expected 'mach-o-universal' to be 'file'); all four pass after. I also generated the issue's exact class files (57-byte and 4,060-byte, file reports "compiled Java class data, version 65.0") and confirmed both now classify as file/non-executable through the real classifier, in a temporary test I removed afterwards.
  • User-visible CLI/MCP output (if applicable): occurrence labels for a class file changed from {"kind":"executable","format":"mach-o-universal"} to {"kind":"resource","format":"file"}, observed through classifyArtifactContent, the same function the inventory path calls. No full inspect-artifact CLI run (needs a build); the remaining gap is stated, not assumed.
  • Remaining proof gaps: none beyond the CLI run 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 --project adapters src/artifacts/inventory/ArtifactGraphConstruction.test.ts — 4 passed
  • npx vitest run --project adapters src/artifacts — 14 files, 100 passed
  • npx vitest run --project boundary tests/boundary/filesystem/artifactMzInventory.test.ts — 3 passed
  • npm run verify:test-discovery — 972 test files discovered exactly once
  • npm run check:fast — typecheck and lint, 2 tasks successful

Compatibility, safety, and release

  • Breaking changes or migration steps: none. The behavior change only affects 0xcafebabe-prefixed bytes whose major-version field is >= 45; real FAT binaries are unaffected (covered by tests).
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; pure byte classification, no provider involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; the change only corrects a mislabel. No new parsing or execution.

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/2329 **Author:** [@sx4im](https://github.com/sx4im) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/2317-class-file-mislabel` --- ### 📝 Commits (1) - [`0f7d3f7`](https://github.com/morluto/rea/commit/0f7d3f7f9f48bea0ad0b23320f5bfec6a80c9c0d) fix(inventory): stop labeling JVM class files as universal Mach-O ### 📊 Changes **2 files changed** (+71 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `src/artifacts/inventory/ArtifactGraphConstruction.test.ts` (+58 -0) 📝 `src/artifacts/inventory/ArtifactGraphConstruction.ts` (+13 -1) </details> ### 📄 Description ## Summary Fixes #2317. `classifyArtifactBytes` in `src/artifacts/inventory/ArtifactGraphConstruction.ts` returned `"mach-o-universal"` for every prefix starting with `CA FE BA BE`. JVM class files share that magic with FAT Mach-O headers, so `inspect-artifact` on a JAR or ZIP reported each `.class` entry as `artifact_kind: executable`, `artifact_format: mach-o-universal`, the same labels a real universal binary in the same archive gets. ## Problem and expected behavior Bytes 4-7 of a class file are the class-file `minor_version`/`major_version`, not the FAT `nfat_arch`. The issue asks for a non-Mach-O format and no `executable` kind. This change classifies class files as `file`, so the occurrence kind falls back to the path role (`resource` for `.class` paths) instead of `executable`. ## Change and scope - `classifyArtifactBytes` now checks, for the big-endian `0xcafebabe` magic only, whether bytes 6-7 hold a plausible class-file major version (>= 45, the first version real compilers emit). If so it returns `"file"`. The byte-swapped FAT magics are untouched: class-file bytes are always big-endian per the JVM spec. - Added `src/artifacts/inventory/ArtifactGraphConstruction.test.ts` with 4 tests. - Left out: a dedicated `java-class` format. That would extend the artifact format schema and touch every consumer switch; the issue explicitly accepts `file`. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Routine bug fix inside existing boundaries; no new provider or capability, so no maintainer scope decision is needed. ## Contract and boundary impact - Semantic owner and earliest changed stage: artifact inventory byte classification (`classifyArtifactBytes`), consumed by `classifyArtifactContent` and the ZIP scan reader. - Contribution scope fit and linked maintainer decision: routine fix within existing boundaries; not applicable. - CLI and MCP/tool-catalog contract: none. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: class-file occurrences now report `artifact_format: file` (kind `resource` for `.class` paths) instead of the unsupported Mach-O labels. Real FAT binaries keep their labels. 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/inventory/ArtifactGraphConstruction.test.ts` (4 tests). - Base reproduction or other evidence: TDD. The two class-file tests failed before the fix (`expected 'mach-o-universal' to be 'file'`); all four pass after. I also generated the issue's exact class files (57-byte and 4,060-byte, `file` reports "compiled Java class data, version 65.0") and confirmed both now classify as `file`/non-executable through the real classifier, in a temporary test I removed afterwards. - User-visible CLI/MCP output (if applicable): occurrence labels for a class file changed from `{"kind":"executable","format":"mach-o-universal"}` to `{"kind":"resource","format":"file"}`, observed through `classifyArtifactContent`, the same function the inventory path calls. No full `inspect-artifact` CLI run (needs a build); the remaining gap is stated, not assumed. - Remaining proof gaps: none beyond the CLI run noted above. 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 - `npx vitest run --project adapters src/artifacts/inventory/ArtifactGraphConstruction.test.ts` — 4 passed - `npx vitest run --project adapters src/artifacts` — 14 files, 100 passed - `npx vitest run --project boundary tests/boundary/filesystem/artifactMzInventory.test.ts` — 3 passed - `npm run verify:test-discovery` — 972 test files discovered exactly once - `npm run check:fast` — typecheck and lint, 2 tasks successful ## Compatibility, safety, and release - Breaking changes or migration steps: none. The behavior change only affects `0xcafebabe`-prefixed bytes whose major-version field is >= 45; real FAT binaries are unaffected (covered by tests). - Real Hopper/Ghidra, browser, or OS coverage: not applicable; pure byte classification, no provider involved. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none; the change only corrects a mislabel. No new parsing or execution. ## 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:04:30 +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#5166
No description provided.