Repository navigation
feat(native): inspect a universal Mach-O slice in Go and Rust metadata readers - #6219
Conversation
…a readers inspect_go_binary and inspect_rust_binary refused universal Mach-O files and offered no slice selection, so hosts without lipo could not inspect them. Both now accept architecture (x86, x86_64, arm, arm64). One selector reads REA's own FAT table, validates the slice range, alignment and header CPU, and returns the thin image with its macho-selected-image-v1 identity. The universal file stays the artifact; results add selected_slice and keep every source range a file offset. Missing, absent, duplicate or misplaced selections fail on architecture and list the slices present. Subject format mach-o-universal now has one owner shared by the services and the retained Go/Rust views. Fixes #4102 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; both previous findings are fixed and no new blocking issue was found. SummaryAdds explicit architecture selection for universal Mach-O files in the Go and Rust inspectors.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read stable artifact] --> B[Select native image]
B --> C[Thin image: use whole file]
B --> D[Universal Mach-O: require architecture]
D --> E[Validate selected slice]
C --> F[Read Go or Rust metadata]
E --> F
F --> G[Translate offsets into original file]
G --> H[Report artifact and optional selected_slice]
Reviews (2) · Last reviewed commit: "fix(native): reject damaged universal fi..." · Reviewed by Greptile |
…ice reports A FAT table whose slice could not be read was treated as a non-universal file, so callers were told to omit architecture. Its reason now fails on path. Go and Rust reports with a selected slice must be Mach-O and name the slice's CPU family, through one shared agreement check. The CLI architecture flag is described in help. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes #4102 (option 1 in the issue).
Before: a universal input failed with
unsupported_target: Universal/fat Mach-O containers require selecting a thin slice, and the tools had no parameter to select one. After:architecture: "arm64"(CLI--architecture arm64) inspects that slice directly, and provenance stays tied to the universal file.Problem and expected behavior
Many macOS releases ship only universal binaries. The issue's example was the GitHub CLI's universal pkg; here I used Tor Browser's
lyrebirdand Cursor'scursor-tunnel. REA already parses FAT tables structurally (readFatContainerHeader,classifyFatContainerIdentity), but these two inspectors only refused. Expected: select a slice by CPU family, record its offset, size and CPU, keep the parent identity, and list the available architectures when the selection is missing or wrong.Change and scope
src/native/metadata/MachoSliceSelection.tsis the single selector. It parses the FAT table, confirms the slices are Mach-O (JVM class files sharing the magic still pass through to the image reader), and matches the requested CPU family. It then validates the slice's range and alignment, and checks that the slice's own Mach-O header CPU type/subtype agrees with the table. The result is the thin bytes, their file offset, and amacho-selected-image-v1identity. The identity reuses the existing provider-neutral schema, includingcontainer_table_sha256computed over header plus table as the Hopper path does. Failures are a typedResult:architectureissues (missing, absent, several matches, or given for a non-universal file) versusmalformedcontainers.header_offset,version_location,module_location; Rust.dep-v0file_offsetand rustc-path hash offsets.artifactstays the universal file (SHA-256, size). Schemas add optionalselected_slicewith a refinement that every reported range lies inside the slice. It is optional so previously retained Evidence still parses ininspect_analysis_view.architectureisx86 | x86_64 | arm | arm64, REA'sBinaryArchitecturenames. They now live once inmachoTargetSelection.ts(MACHO_CPU_TYPES), which the existingmachoTargetSelectionMatchesArchitecturealso uses.mach-o-universal. The services and the retained Go/Rust views each re-derivedformat === "macho" ? "mach-o" : format, and the views rejected the new value. That mapping now has one owner (metadataReportSubjectFormat), used by all four.detail: "summary") carryselected_slice.selectImage(binary_architecture: arm64 | amd64, its own public failure codes) could move onto this selector, but that changes its public vocabulary and error codes, so it is left for a follow-up.extract_artifact'slipodependency (option 2 in the issue) is also unchanged.Contract and boundary impact
selectNativeImage(before any image parsing); subject format inmachoTargetSelection.ts.architectureinput on both tools (MCP + CLI--architecture); additive optionalselected_sliceoutput; universal inputs now fail asinvalid_requestonarchitectureinstead ofunsupported_target.lipo.format: mach-o-universalwith the slice'sarchitecture.Expected effects:
Evidence and regression coverage
tests/boundary/mcp/universalSliceMcp.test.ts, through the MCP server):artifactis the universal file,selected_sliceholds the exact offset/length/CPU and table digest, and ranges are file offsets that slice back togo1.26.1. Subject ismach-o-universal/arm64, parameters recordarchitecture, input and output are validated against the advertised JSON Schemas with Ajv, anddetail: "summary"for x86_64 carriesselected_slice.x86_64 (subtype 0x3), arm64 (subtype 0x0);architectureon a thin image; two arm64 slices (ambiguous); and a FAT entry whose CPU disagrees with the slice header (malformedpath)..dep-v0and rustc offsets shifted by the slice offset; a missing selection fails onarchitecture.pathwith the FAT reason, with or withoutarchitecture. Reports whoseselected_slicecontradicts their own format or CPU (amd64orelf) are rejected by the Go/Rust schemas through one sharedselectedSliceAgreesWithReportcheck. The CLI--architectureflag is described in help (cliOptionAliases).tests/fixtures/universalMacho.tsbuilds FAT32 fixtures from existing thin fixtures.origin/mainbuild:Baseline on universal input:
inspect-go-binary …/Tor Browser.app/…/lyrebirdandinspect-rust-binary …/Cursor.app/…/bin/cursor-tunnelboth returnunsupported_target … require selecting a thin slice.This PR with
--architecturevs baseline on thelipo -thin-extracted slice. Every field is identical except offsets, which are shifted by exactlyselected_slice.offset:lyrebird(Go 1.22.12, 32 MB)conjure-client(Go)cursor-tunnel(Rust)@vscode/ripgreprg(Rust)Cost: universal-with-selection 0.70–1.14 s wall, 0.93–1.07 s CPU, 354–361 MiB peak RSS (Go, 3 runs). The same branch on the 15 MB thin slice: 0.62 s, 0.94 s CPU, 327 MiB. The extra ~30 MiB is the 32 MB universal file read once; no slice copy is made (
subarray). Report size is unchanged apart from the ~10-byteselected_slice(17,370 vs 17,360 bytes); the summary is 4.2 KB..dep-v0data was available locally (both real Rust binaries carry only rustc paths), so the dependency-section shift is covered by the fixture test. Linux/Windows hosts were not run locally (CI).For evidence-bearing changes:
Validation performed
npm run test:focused -- tests/boundary/mcp/universalSliceMcp.test.ts tests/boundary/mcp/goBinaryMcp.test.ts tests/boundary/mcp/rustBinaryMcp.test.ts tests/boundary/mcp/goBinaryViews.test.ts tests/boundary/go/goBinaryImage.test.ts tests/boundary/rust/rustBinaryImage.test.ts tests/acceptance/goBinaryCli.test.ts tests/acceptance/rustBinaryCli.test.ts tests/acceptance/rustDependencyViews.test.ts src/application/go/GoBinaryService.test.ts src/application/rust/RustBinaryService.test.ts tests/boundary/providers/native/artifactProvider.machOSlices.test.ts tests/boundary/filesystem/binaryTarget.test.ts tests/boundary/mcp/absoluteLocalPathSchema.test.ts tests/process-global/stableArtifactConsumers.test.ts tests/boundary/cli/artifactInputLimits.test.ts— 16 files, 326 tests passed.npm run test:focused -- tests/boundary/mcp/universalSliceMcp.test.ts tests/boundary/cli/cliOptionAliases.test.ts tests/boundary/mcp/goBinaryMcp.test.ts tests/boundary/mcp/rustBinaryMcp.test.ts tests/boundary/mcp/goBinaryViews.test.ts tests/acceptance/rustDependencyViews.test.ts tests/boundary/go/goBinaryImage.test.ts tests/boundary/rust/rustBinaryImage.test.ts— 8 files, 141 tests passed.npm run check:fast— passed.npm run format:check— passed.npm run docs:check— passed.npm run build:cachedon both trees).Compatibility, safety, and release
architecturenow returnsinvalid_request(patharchitecture, slices listed) instead ofunsupported_target. That call never succeeded before, and the new error is the actionable one.Author readiness
Human owner: @kaoru0822-kitauji
Before merge
type(scope): outcome.🤖 Generated with Claude Code