[PR #2201] [MERGED] fix(ida): thin the selected FAT slice into the private headless input #5079

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

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2201
Author: @akushonkamen
Created: 10/12/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @morluto

Base: main ← Head: fix/2139-ida-thin-fat-slice


📝 Commits (1)

  • 8584547 fix(ida): thin the selected FAT slice into the private headless input

📊 Changes

9 files changed (+242 additions, -29 deletions)

View changed files

📝 src/domain/analysisSnapshot.test.ts (+19 -8)
📝 src/domain/binaryTarget.ts (+17 -6)
📝 src/domain/binaryTargetTypes.ts (+15 -6)
📝 src/ghidra/GhidraProvider.behavior.test.ts (+1 -0)
📝 src/hopper/HopperAnalysisProfile.test.ts (+1 -0)
📝 src/ida/IdaSessionClient.ts (+2 -1)
📝 src/ida/IdaWorkspace.ts (+55 -8)
➕ src/ida/IdaWorkspaceThinning.test.ts (+131 -0)
📝 tests/boundary/providers/native/artifactProvider.universalExtraction.test.ts (+1 -0)

📄 Description

Summary

Universal Mach-O admission resolved and reported the host-preferred slice's architecture, but the IDA provider's private input copy handed the whole FAT container to upstream idalib, which then picked its own slice (x86_64 for /bin/cat) while Evidence labeled the session arm64. FAT parsing now exports the selected slice's byte range as universalSlice, and the private input copy writes exactly those bytes.

Fixes #2139

Problem and expected behavior

On an arm64 macOS host with the IDA provider (headless idalib-mcp), opening a universal binary reports architecture: "arm64" in open_binary, every Evidence subject, and the analysis profile, while the analysed code is the x86_64 slice (push rbp; mov rbp, rsp SysV prologue on start). The violated invariant: the architecture recorded in Evidence must describe the bytes the provider actually analyses.

Root cause, read from src at the base of this branch:

  • parseFatMachO (src/domain/binaryTarget.ts:103; :113-:159 at base 5190843f8) already resolved the host-compatible preferred slice and computed its byte range, but the resolved target kept the whole FAT path with no slice offset/size exported.
  • BinaryTargetResolver.ts:70 uses process.arch only for the reported architecture; the resolved path stays the whole container.
  • IdaWorkspace.copyInput (src/ida/IdaWorkspace.ts:64) copied the whole FAT into the private workspace, so upstream idalib chose its own slice.

Change and scope

  • The FAT parse result and BinaryTarget's mach-o-universal variant now carry a required universalSlice { offset, size } (src/domain/binaryTargetTypes.ts:34, src/domain/binaryTarget.ts:174). Container-identity semantics are unchanged: mach-o-universal remains the container format across Evidence, snapshots, and provider routing, and sha256 stays the whole-file digest.
  • copyInput became a single-pass bounded streaming copy (64 KB chunks): the whole-file sha256 still anchors the copy against admission-time source changes, but only the selected slice's bytes are written, and the digest of the thinned product is exposed as inputSha256 (src/ida/IdaWorkspace.ts:38).
  • The post-operation identity check in IdaSessionClient.ts:510 accordingly anchors the thinned product instead of the whole container.
  • Thin targets keep the whole-file copy. Intentionally not included: live IDA validation (no license available here — disclosed below), and any change to the snapshot cache key.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain binary-target parsing owns the slice byte range; earliest changed stage is target resolution.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: the IDA provider's private input for mach-o-universal targets is now the selected slice, so upstream idalib can no longer pick a different slice than the reported architecture. Other providers and thin formats are untouched.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence subject architecture now describes the analysed bytes. The snapshot cache key remains the whole-FAT sha256, so snapshots produced before this fix can theoretically still replay against the whole container — disclosed as a known gap.
  • Process execution, authorization, cleanup, or containment impact: none; the copy stays inside the existing private workspace with the same bounded-write guarantees.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added: src/ida/IdaWorkspaceThinning.test.ts (5 tests: arm64 slice thinning, x86_64 slice when the host is intel, whole-file copy for thin targets, rejection of a universal source changed after admission, headless session bound to the thinned input identity). analysisSnapshot and binaryTargetTypes fixtures updated for the required universalSlice.

  • Base reproduction (executed): on clean origin/main 58fb37207 (this branch's rebased parent) the new suite fails 3 failed | 2 passed (5) — the two thinning tests and the whole-file-copy test fail (src/ida/IdaWorkspaceThinning.test.ts:48, :74, :91: the copied input is the whole FAT, not the 32-byte slice, and inputSha256 is undefined) — and passes with this change.

  • Remaining proof gaps: no live IDA analysis (unlicensed here); universal-slice behavior verified with synthetic lipo fixtures, not real-IDA sessions.

  • 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/ida/IdaWorkspaceThinning.test.ts — 5 passed (5) with the change; 3 failed | 2 passed on clean origin/main 58fb37207 (base reproduction above)
  • npx vitest run --project adapters src/ida/ — 12 files, 116 passed
  • npx vitest run --project domain --project services — 201 files, 2854 passed, 3 skipped (full projects after rebasing onto 58fb37207)
  • npx vitest run --project adapters src/ghidra/GhidraProvider.behavior.test.ts src/hopper/HopperAnalysisProfile.test.ts — 2 files, 50 passed
  • npx vitest run --project boundary tests/boundary/filesystem/binaryTarget.test.ts tests/boundary/providers/native/artifactProvider.universalExtraction.test.ts — 2 files, 49 passed
  • npx vitest run --project mcp-boundary tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts — 1 file, 2 passed
  • npx oxfmt . (no-op; tree unchanged) then npx vitest run src/ida/ src/domain/binaryTarget.test.ts — 13 files, 151 passed
  • npx vitest run src/ida/IdaWorkspaceThinning.test.ts src/ida/IdaWorkspaceOwnership.test.ts src/ida/IdaSessionClient.test.ts — 3 files, 45 passed
  • npx tsc --noEmit — clean
  • npx oxlint — 866 warnings and 0 errors, identical multiset to a clean origin/main 58fb37207 worktree (verified by diffing normalized warning triples; the only differences are two pre-existing warnings whose line numbers shifted inside edited files — zero new)
  • npx oxfmt --check on the 9 changed files — all pass
  • npx knip — 1 unresolved import (#javascript-analysis-worker), identical on clean origin/main (pre-existing)
  • Scratch end-to-end fixture (executed during validation of this branch, removed afterwards): clang -arch arm64 / -arch x86_64 + lipo -create built a real 33224-byte universal (x86_64@4096+4272, arm64@16384+16840); the copyInput product was byte-identical to the clang -arch arm64 original, LE magic 0xfeedfacf, cputype 0x0100000c, length = universalSlice.size = 16840
  • Not run: live IDA analysis — no license/authorization available in this environment (disclosed above)

Compatibility, safety, and release

  • Breaking changes or migration steps: none; no public CLI/MCP contract changes.
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra/Hopper behavior suites pass (2 files / 50 tests); macOS FAT behavior covered by synthetic universal fixtures, not a licensed IDA install.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the bounded streaming copy keeps the digest anchor against source swaps between admission and copy; no new subprocesses, network, or elevated access.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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. (No output format change; the fix corrects which bytes are analysed.)
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🤖 Generated with Claude Code


🔄 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/2201 **Author:** [@akushonkamen](https://github.com/akushonkamen) **Created:** 10/12/2026 **Status:** ✅ Merged **Merged:** 10/12/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/2139-ida-thin-fat-slice` --- ### 📝 Commits (1) - [`8584547`](https://github.com/morluto/rea/commit/8584547ab1c412baed85749b0a2f22d600c4611f) fix(ida): thin the selected FAT slice into the private headless input ### 📊 Changes **9 files changed** (+242 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `src/domain/analysisSnapshot.test.ts` (+19 -8) 📝 `src/domain/binaryTarget.ts` (+17 -6) 📝 `src/domain/binaryTargetTypes.ts` (+15 -6) 📝 `src/ghidra/GhidraProvider.behavior.test.ts` (+1 -0) 📝 `src/hopper/HopperAnalysisProfile.test.ts` (+1 -0) 📝 `src/ida/IdaSessionClient.ts` (+2 -1) 📝 `src/ida/IdaWorkspace.ts` (+55 -8) ➕ `src/ida/IdaWorkspaceThinning.test.ts` (+131 -0) 📝 `tests/boundary/providers/native/artifactProvider.universalExtraction.test.ts` (+1 -0) </details> ### 📄 Description ## Summary Universal Mach-O admission resolved and reported the host-preferred slice's architecture, but the IDA provider's private input copy handed the whole FAT container to upstream idalib, which then picked its own slice (x86_64 for `/bin/cat`) while Evidence labeled the session arm64. FAT parsing now exports the selected slice's byte range as `universalSlice`, and the private input copy writes exactly those bytes. Fixes #2139 ## Problem and expected behavior On an arm64 macOS host with the IDA provider (headless `idalib-mcp`), opening a universal binary reports `architecture: "arm64"` in `open_binary`, every Evidence subject, and the analysis profile, while the analysed code is the x86_64 slice (`push rbp; mov rbp, rsp` SysV prologue on `start`). The violated invariant: the architecture recorded in Evidence must describe the bytes the provider actually analyses. Root cause, read from `src` at the base of this branch: - `parseFatMachO` (`src/domain/binaryTarget.ts:103`; `:113`-`:159` at base `5190843f8`) already resolved the host-compatible preferred slice and computed its byte range, but the resolved target kept the whole FAT path with no slice offset/size exported. - `BinaryTargetResolver.ts:70` uses `process.arch` only for the *reported* architecture; the resolved `path` stays the whole container. - `IdaWorkspace.copyInput` (`src/ida/IdaWorkspace.ts:64`) copied the whole FAT into the private workspace, so upstream idalib chose its own slice. ## Change and scope - The FAT parse result and `BinaryTarget`'s `mach-o-universal` variant now carry a required `universalSlice { offset, size }` (`src/domain/binaryTargetTypes.ts:34`, `src/domain/binaryTarget.ts:174`). Container-identity semantics are unchanged: `mach-o-universal` remains the container format across Evidence, snapshots, and provider routing, and `sha256` stays the whole-file digest. - `copyInput` became a single-pass bounded streaming copy (64 KB chunks): the whole-file sha256 still anchors the copy against admission-time source changes, but only the selected slice's bytes are written, and the digest of the thinned product is exposed as `inputSha256` (`src/ida/IdaWorkspace.ts:38`). - The post-operation identity check in `IdaSessionClient.ts:510` accordingly anchors the thinned product instead of the whole container. - Thin targets keep the whole-file copy. Intentionally not included: live IDA validation (no license available here — disclosed below), and any change to the snapshot cache key. ## Contract and boundary impact - Semantic owner and earliest changed stage: domain binary-target parsing owns the slice byte range; earliest changed stage is target resolution. - CLI and MCP/tool-catalog contract: none. - Provider, bridge, target-format, or platform compatibility: the IDA provider's private input for `mach-o-universal` targets is now the selected slice, so upstream idalib can no longer pick a different slice than the reported architecture. Other providers and thin formats are untouched. - Evidence, artifact, provenance, or reconstruction contract: Evidence subject architecture now describes the analysed bytes. The snapshot cache key remains the whole-FAT sha256, so snapshots produced before this fix can theoretically still replay against the whole container — disclosed as a known gap. - Process execution, authorization, cleanup, or containment impact: none; the copy stays inside the existing private workspace with the same bounded-write guarantees. - Generated metadata, package, or installation impact: none. ## Evidence and regression coverage - Tests added: `src/ida/IdaWorkspaceThinning.test.ts` (5 tests: arm64 slice thinning, x86_64 slice when the host is intel, whole-file copy for thin targets, rejection of a universal source changed after admission, headless session bound to the thinned input identity). `analysisSnapshot` and `binaryTargetTypes` fixtures updated for the required `universalSlice`. - Base reproduction (executed): on clean `origin/main` `58fb37207` (this branch's rebased parent) the new suite fails **3 failed | 2 passed (5)** — the two thinning tests and the whole-file-copy test fail (`src/ida/IdaWorkspaceThinning.test.ts:48`, `:74`, `:91`: the copied input is the whole FAT, not the 32-byte slice, and `inputSha256` is `undefined`) — and passes with this change. - Remaining proof gaps: no live IDA analysis (unlicensed here); universal-slice behavior verified with synthetic `lipo` fixtures, not real-IDA sessions. - [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/ida/IdaWorkspaceThinning.test.ts` — 5 passed (5) with the change; 3 failed | 2 passed on clean `origin/main` `58fb37207` (base reproduction above) - `npx vitest run --project adapters src/ida/` — 12 files, 116 passed - `npx vitest run --project domain --project services` — 201 files, 2854 passed, 3 skipped (full projects after rebasing onto `58fb37207`) - `npx vitest run --project adapters src/ghidra/GhidraProvider.behavior.test.ts src/hopper/HopperAnalysisProfile.test.ts` — 2 files, 50 passed - `npx vitest run --project boundary tests/boundary/filesystem/binaryTarget.test.ts tests/boundary/providers/native/artifactProvider.universalExtraction.test.ts` — 2 files, 49 passed - `npx vitest run --project mcp-boundary tests/boundary/mcp/nativeSignatureTargetBindingMcp.test.ts` — 1 file, 2 passed - `npx oxfmt .` (no-op; tree unchanged) then `npx vitest run src/ida/ src/domain/binaryTarget.test.ts` — 13 files, 151 passed - `npx vitest run src/ida/IdaWorkspaceThinning.test.ts src/ida/IdaWorkspaceOwnership.test.ts src/ida/IdaSessionClient.test.ts` — 3 files, 45 passed - `npx tsc --noEmit` — clean - `npx oxlint` — 866 warnings and 0 errors, identical multiset to a clean `origin/main` `58fb37207` worktree (verified by diffing normalized warning triples; the only differences are two pre-existing warnings whose line numbers shifted inside edited files — zero new) - `npx oxfmt --check` on the 9 changed files — all pass - `npx knip` — 1 unresolved import (`#javascript-analysis-worker`), identical on clean `origin/main` (pre-existing) - Scratch end-to-end fixture (executed during validation of this branch, removed afterwards): `clang -arch arm64` / `-arch x86_64` + `lipo -create` built a real 33224-byte universal (x86_64@4096+4272, arm64@16384+16840); the `copyInput` product was byte-identical to the `clang -arch arm64` original, LE magic `0xfeedfacf`, cputype `0x0100000c`, length = `universalSlice.size` = 16840 - Not run: live IDA analysis — no license/authorization available in this environment (disclosed above) ## Compatibility, safety, and release - Breaking changes or migration steps: none; no public CLI/MCP contract changes. - Real Hopper/Ghidra, browser, or OS coverage: Ghidra/Hopper behavior suites pass (2 files / 50 tests); macOS FAT behavior covered by synthetic universal fixtures, not a licensed IDA install. - Package or release metadata impact: none. - Security, privacy, process, or containment review: the bounded streaming copy keeps the digest anchor against source swaps between admission and copy; no new subprocesses, network, or elevated access. ## Review checklist - [x] This PR addresses a concrete problem or an agreed enhancement. - [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. (No output format change; the fix corrects which bytes are analysed.) - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:03:18 +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#5079
No description provided.