Repository navigation
fix(ida): stop the private input of a universal Mach-O at the end of the selected slice - #2291
Conversation
…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.
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@greptileai review |
|
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. |
|
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 writesbytes.subarray(start - position, end - position)withstart = max(position, slice.offset)andend = min(position + bytes.length, slice.offset + slice.size). For the first chunk that starts after the slice end,end - positionis negative, andBuffer.subarraycounts 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 arm64and-arch arm64eof one source, combined withlipo -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/caffeinatewith 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 whenend > 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
Evidence and regression coverage
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 equalsslice.size, that its bytes equal the slice, and thatinputSha256equals the slice's SHA-256.ec2d251c0with 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 thelipolayout above: onec2d251c0the 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 startstill returns arm64e code at0x100000740, andnpm run verify:idapasses.Validation performed
npm run check:fast,npm run check,npm run verify:test-discovery(950 files) - greennpm run test:focused -- src/ida/IdaWorkspaceThinning.test.ts- 7 passednpm run test:fast- 404 files, 5245 passed, 7 skipped, 0 failedtruefails both new tests (51240 and 59224 bytes)macOS arm64 only; Linux and Windows were not executed.
test:boundarywas not run because no boundary file is touched.Compatibility, safety, and release
Review checklist
type(scope): outcome.