Skip to content

fix(ida): stop the private input of a universal Mach-O at the end of the selected slice - #2291

Merged
morluto merged 2 commits into
morluto:mainfrom
nikolay-dementiev:fix/ida-fat-slice-copy-bounds
Oct 13, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
nikolay-dementiev:fix/ida-fat-slice-copy-bounds

Conversation

@nikolay-dementiev

Copy link
Copy Markdown
Contributor

Summary

When IDA opens a universal Mach-O, REA copies only the selected slice into the private input. The copy also appended the head of the following slice whenever the selected slice ended before a 64 KiB read boundary and another slice followed it. The copy now ends exactly at the selected slice.

Fixes #2285

Regression of #2201, which closed #2139.

Problem and expected behavior

IdaWorkspace.copyInput() reads the admitted source in 64 KiB chunks and writes bytes.subarray(start - position, end - position) with start = max(position, slice.offset) and end = min(position + bytes.length, slice.offset + slice.size). For the first chunk that starts after the slice end, end - position is negative, and Buffer.subarray counts a negative end from the end of the chunk, so it returns a non-empty prefix. Those bytes were written to the private input and added to its digest.

Real reproduction (macOS arm64, IDA Professional 9.1): clang -O0 -arch x86_64, -arch arm64 and -arch arm64e of one source, combined with lipo -create: x86_64 at 4096 (8480 bytes), arm64 at 16384 (33464 bytes), arm64e at 65536 (33464 bytes), 99000 bytes in total. REA selects the arm64 slice on this host; the private copy was 51240 bytes, not 33464. The first 33464 bytes equal the arm64 slice and the last 17776 bytes are the first 17776 bytes of the arm64e slice. IDA still analysed ARM code here because its loader ignored the trailing bytes. /usr/bin/caffeinate with its first slice selected gave 91296 bytes instead of 37456. The bug does not appear when the selected slice is the last one or ends on a 64 KiB boundary.

Expected: the private input is exactly the selected slice (length slice.size, SHA-256 equal to the slice's).

Change and scope

  • src/ida/IdaWorkspace.ts: write and hash a chunk's bytes only when end > start. The whole-source digest check and the copy of non-universal targets are unchanged.

Intentionally not included: no change to slice selection or admission, and no docs change (no document describes the copy semantics beyond "thinned to the selected slice").

Contract and boundary impact

  • Semantic owner and earliest changed stage: the IDA workspace, at the private input copy.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: IDA headless profile with universal Mach-O targets; other formats and providers are unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: the private input digest and the bytes IDA receives now equal the selected slice; nothing else in Evidence changes.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata/package/installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/ida/IdaWorkspaceThinning.test.ts (beside the existing thinning tests, real workspace and real file, no mocks): a 99000-byte universal file with the layout above (synthetic bytes, each slice filled with its own value) and a host that selects the middle slice; and a universal file whose first slice is selected with another slice after it. Each asserts that the private input length equals slice.size, that its bytes equal the slice, and that inputSha256 equals the slice's SHA-256.
  • Base reproduction or other evidence: both new tests fail on ec2d251c0 with the private input at 51240 bytes instead of 33464 and 59224 instead of 37456. Real IDA Professional 9.1 (headless idalib, ida-pro-mcp c133c38, macOS arm64) on the lipo layout above: on ec2d251c0 the private input was 51240 bytes; with this branch it is 33464 bytes and byte-identical to the arm64 slice, IDA still analyses ARM code, rea function /usr/bin/caffeinate start still returns arm64e code at 0x100000740, and npm run verify:ida passes.
  • Remaining proof gaps: only macOS arm64 was exercised; other hosts and IDA versions were not.
  • 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 check:fast, npm run check, npm run verify:test-discovery (950 files) - green
  • npm run test:focused -- src/ida/IdaWorkspaceThinning.test.ts - 7 passed
  • npm run test:fast - 404 files, 5245 passed, 7 skipped, 0 failed
  • Mutation check, reverted: replacing the new guard with true fails both new tests (51240 and 59224 bytes)

macOS arm64 only; Linux and Windows were not executed. test:boundary was not run because no boundary file is touched.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real IDA 9.1 on macOS arm64 (see above); Hopper, Ghidra and browser not applicable.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the private input no longer contains bytes outside the admitted slice.

Review checklist

  • The change addresses a concrete problem, not an unscoped refactor.
  • The PR has one focused outcome, and the title follows type(scope): outcome.
  • Related issue is linked.
  • Tests cover changed behavior and failure paths.
  • Owning docs, contracts, and generated metadata are updated.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

…he selected slice

Cover a universal file larger than one read chunk with another slice after the selected one, for both a middle slice and the first slice.
…the selected slice

A read chunk that starts after the slice produced a negative end offset, and Buffer.subarray counts a negative bound from the end, so the head of the following slice was written to the private input and its digest.
@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.

@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

This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the guard fixes trailing-byte copies without weakening source checks.

Summary

IdaWorkspace.copyInput() now checks that a chunk overlaps the selected Mach-O slice before copying or hashing its bytes.

  • IDA’s private input stops at the end of the selected Mach-O slice.

No actionable issues found. Tests were inspected, not run. Supersession status could not be checked because GitHub access was unauthenticated.

Reviews (1) · Last reviewed commit: "fix(ida): stop the private input of a un..." · Reviewed by Greptile

@morluto
morluto merged commit c6acd19 into morluto:main Oct 13, 2026
31 checks passed
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
@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

2 participants