Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4d3b7a1
feat(ghidra): admit caller-selected matching dSYM companions
jimpablo Oct 12, 2026
f0eb9c4
fix(targets): partition dSYM identity and match the selected slice
jimpablo Oct 12, 2026
104601e
fix(targets): keep legacy query ids and bound companion admission
jimpablo Oct 12, 2026
c219cb9
fix(targets): bound uuid walking and carry companion provenance
jimpablo Oct 12, 2026
ab3bf42
fix(contracts): budget command spans and partition companions by path
jimpablo Oct 12, 2026
11e1002
fix(ghidra): commit companion identity in the analysis profile
jimpablo Oct 12, 2026
731f243
fix(targets): carry companion identity through split mach-o variants
jimpablo Oct 12, 2026
03f9058
fix(targets): charge traversal reads and bound staged member copies
jimpablo Oct 13, 2026
d3fe4a0
fix(ghidra): document and enforce dSYM admission resource budgets
morluto Oct 13, 2026
dbf8d2c
fix(ghidra): preserve dSYM resource refusals and staging coverage
morluto Oct 13, 2026
dea1571
fix(ghidra): stream dSYM UUID commands through their format owner
morluto Oct 13, 2026
437eb2d
fix(ghidra): retain dSYM input ownership and shared format semantics
morluto Oct 13, 2026
26effd7
fix(ghidra): preserve dSYM companion admission facts
morluto Oct 13, 2026
0ab02a0
fix(ghidra): retain failed source copy owners
morluto Oct 13, 2026
58af2fb
fix(targets): settle merged companion types and heap stub props
jimpablo Oct 14, 2026
7bafafc
fix(macho): retain dSYM admission resources
morluto Oct 13, 2026
71cee08
fix(ghidra): preserve dSYM identity and cleanup failures
morluto Oct 13, 2026
7e7d3d2
fix(targets): settle merged types, heap stub props, and split oversiz…
jimpablo Oct 14, 2026
b735fd3
fix(ghidra): rebase onto main, drop hanging copy helper, restore staging
jimpablo Oct 27, 2026
529d444
fix(targets): settle second rebase: weave dsym admission into new res…
jimpablo Oct 28, 2026
07da6f1
fix(targets): restore upstream code dropped during rebase
jimpablo Oct 28, 2026
1a2fa6a
fix(contracts): omit debug_companion from bare Mach-O summaries
jimpablo Oct 28, 2026
0b4ae16
fix(targets): address companion admission review findings
jimpablo Oct 28, 2026
aa20d1d
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
6b32456
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
4483d21
fix(ghidra): harden dSYM companion admission, staging ownership, and …
jimpablo Nov 5, 2026
a7e17e6
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
d90dcca
fix(ghidra): preserve dSYM cleanup primary causes and reuse Mach-O lo…
jimpablo Nov 5, 2026
8bec33a
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
c50d6f5
fix(ghidra): reject dsym_path in existing-project mode and enforce de…
jimpablo Nov 5, 2026
636d664
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
30e21fa
fix(macho): separate companion EOF truncation from traversal budget a…
jimpablo Nov 5, 2026
97a2e09
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 5, 2026
fbef489
fix(cli): reuse absoluteLocalPathStringSchema for --dsym-path option
jimpablo Nov 5, 2026
f51fb61
fix(macho): clamp initial UUID prefix reads to remaining traversal bu…
jimpablo Nov 5, 2026
2c150cb
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 8, 2026
417b628
fix(dsym): enforce .dSYM bundle directory naming and pin companion di…
jimpablo Nov 8, 2026
0988275
fix(dsym): preserve close cancellation, reject ambiguous FAT slices, …
jimpablo Nov 8, 2026
390918f
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 8, 2026
a0cac2a
fix(dsym): preserve close cancellation during directory and staging c…
jimpablo Nov 8, 2026
a84c8a8
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 8, 2026
6a32f35
fix(dsym): preserve member and directory refusals over final-close ca…
jimpablo Nov 8, 2026
c72fb30
docs(specs): add Mach-O dSYM companion feature specification
jimpablo Nov 8, 2026
dd33451
docs(specs): align module and checkpoint test paths in dsym plan
jimpablo Nov 8, 2026
a6f3b94
docs(specs): match symlink policy and saved-project error contract
jimpablo Nov 8, 2026
ca7d919
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 8, 2026
c50bf0d
fix(dsym): skip checkpoint restaging and harden companion identity
jimpablo Nov 8, 2026
2152709
test(mcp): validate session dsym_path outputs via toolContract
jimpablo Nov 8, 2026
4d3ad8f
fix(dsym): retain both companion and target cleanup owners on dual cl…
jimpablo Nov 8, 2026
57f2edc
fix(dsym): reject duplicate FAT target CPU identities before slice na…
jimpablo Nov 8, 2026
9560a44
fix(dsym): keep post-admission member read faults fatal across close …
jimpablo Nov 9, 2026
9f36e1f
fix(dsym): use tagged member failure union and guard opaque abort rea…
jimpablo Nov 9, 2026
bdd456e
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 10, 2026
616d5dc
chore(dsym): merge upstream/main and remove unused imports
jimpablo Nov 10, 2026
3f8c9ce
chore(dsym): restore upstream files modified by lint-staged during merge
jimpablo Nov 10, 2026
92d9d79
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 11, 2026
b244242
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 15, 2026
ea7612b
fix(contracts): preserve headerless issues alongside dsym_path and ex…
jimpablo Nov 15, 2026
03b3ff8
chore(dsym): restore upstream javascriptStaticAnalysis modified by li…
jimpablo Nov 15, 2026
4d761f9
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 16, 2026
858d124
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 16, 2026
65d40a3
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 17, 2026
b32d1bf
Merge remote-tracking branch 'upstream/main' into feat/dsym-companion…
jimpablo Nov 21, 2026
cbddb9d
test(target): verify dsym_path rejection on Hopper and IDA databases
jimpablo Nov 21, 2026
336d28c
fix(ghidra): preserve dSYM parse failures, refusals, and staging owne…
jimpablo Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(targets): bound uuid walking and carry companion provenance
  • Loading branch information
jimpablo committed Oct 28, 2026
commit c219cb9d8605e4d2ae8a38cf7fb1191a7a8f7f6d
24 changes: 18 additions & 6 deletions src/application/DebugCompanionAdmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export const readMachoFileUuidEntries = async (
magic === 0xcafebabe ||
magic === 0xcafebabf ||
magic === 0xbebafeca ||
magic === 0xbebafbfa;
magic === 0xbfbafeca;
if (!universal) return readMachoUuidEntries(prefix.value);
const wide = magic === 0xcafebabf || magic === 0xbebafbfa;
const wide = magic === 0xcafebabf || magic === 0xbfbafeca;
// The architecture table follows the observed container byte order.
const big = magic === 0xcafebabe || magic === 0xcafebabf;
const read32 = big
Expand Down Expand Up @@ -236,19 +236,31 @@ export const admitDebugCompanion = async (input: {
input.targetSize,
);
if (!targetEntries.ok) return err({ reason: targetEntries.error });
// Mirror the target parser's FAT selection: the first slice of each CPU
// family is the one REA imports, so only that slice's UUID can admit a
// companion (a same-family sibling such as x86_64h is not the import).
const selectedCpuTypes = CPU_TYPES[input.architecture];
const importedFamilies = new Set<number>();
const selectedUuids = targetEntries.value
.filter(({ cpuType }) => selectedCpuTypes.includes(cpuType))
.filter(({ cpuType }) => {
const family = selectedCpuTypes.find(
(candidate) => candidate === cpuType,
);
if (family === undefined || importedFamilies.has(family)) return false;
importedFamilies.add(family);
return true;
})
.map(({ uuid }) => uuid);
if (selectedUuids.length === 0)
return err({
reason: `the target image declares no LC_UUID for the selected ${input.architecture} slice`,
});
for (const memberPath of memberPaths) {
throwIfCancelled(signal);
const memberHandle = await open(memberPath, constants.O_RDONLY).catch(
() => undefined,
);
const memberHandle = await open(
memberPath,
constants.O_RDONLY | constants.O_NONBLOCK,
).catch(() => undefined);
if (memberHandle === undefined) continue;
try {
const initial = await memberHandle.stat();
Expand Down
11 changes: 11 additions & 0 deletions src/application/binary/BinaryTargetSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,15 @@ export const binaryTargetSummary = (target: BinaryTarget) =>
...(target.format === "raw-binary" || target.format === "gamecube-dol"
? { entry_point: target.entryPoint }
: {}),
...(target.format !== "mach-o" && target.format !== "mach-o-universal"
? {}
: target.debugCompanion === undefined
? {}
: {
debug_companion: {
source_path: target.debugCompanion.sourcePath,
uuid: target.debugCompanion.uuid,
member_sha256: target.debugCompanion.memberSha256,
},
}),
});
73 changes: 73 additions & 0 deletions src/domain/machoDebugCompanion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,79 @@ describe("UUID entry attribution", () => {
});
});

describe("LC_UUID admission invariants", () => {
const uuid = "A1B2C3D4-E5F6-0789-ABCD-EF0123456789";
const thinWithCommands = (
commands: readonly {
readonly kind: number;
readonly size: number;
readonly payload?: Buffer;
}[],
): Buffer => {
const total = commands.reduce((sum, c) => sum + c.size, 0);
const bytes = Buffer.alloc(32 + total);
bytes.writeUInt32LE(0xfeedfacf, 0);
bytes.writeUInt32LE(0x0100000c, 4);
bytes.writeUInt32LE(commands.length, 16);
bytes.writeUInt32LE(total, 20);
let cursor = 32;
for (const command of commands) {
bytes.writeUInt32LE(command.kind, cursor);
bytes.writeUInt32LE(command.size, cursor + 4);
command.payload?.copy(bytes, cursor + 8);
cursor += command.size;
}
return bytes;
};
const uuidPayload = (text: string): Buffer =>
Buffer.from(text.replace(/-/gu, ""), "hex");

it("rejects a second LC_UUID in one image as a conflicting identity", () => {
const bytes = thinWithCommands([
{ kind: 0x1b, size: 8 + 16, payload: uuidPayload(uuid) },
{ kind: 0x1b, size: 8 + 16, payload: uuidPayload(uuid) },
]);
expect(readMachoUuids(bytes).ok).toBe(false);
});
it("ignores a UUID payload beyond the declared command span", () => {
// ncmds=1, sizeofcmds=8: the trailing LC_UUID bytes are not a command.
const bytes = thinWithCommands([{ kind: 0x29, size: 8 }]);
Buffer.alloc(8 + 16).forEach(() => undefined);
const trailing = Buffer.alloc(8 + 16);
trailing.writeUInt32LE(0x1b, 0);
trailing.writeUInt32LE(8 + 16, 4);
uuidPayload(uuid).copy(trailing, 8);
const withTrailing = Buffer.concat([bytes, trailing]);
expect(readMachoUuids(withTrailing)).toEqual({ ok: true, value: [] });
});
it("rejects a short prefix instead of crashing on field access", () => {
const bytes = Buffer.alloc(12);
bytes.writeUInt32LE(0xcffaedfe, 0);
const result = readMachoUuids(bytes);
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error).toContain("truncated");
});
it("decodes a byte-swapped FAT64 container", () => {
const slice = withUuidLoadCommand("44444444-4444-4444-4444-444444444444");
const entrySize = 32;
const headerSize = 8 + entrySize;
const bytes = Buffer.alloc(headerSize + slice.length);
bytes.writeUInt32LE(0xcafebabf, 0); // reads 0xbfbafeca big-endian
bytes.writeUInt32LE(1, 4);
const entry = 8;
bytes.writeUInt32LE(0x01000007, entry);
bytes.writeBigUInt64LE(BigInt(headerSize), entry + 8);
bytes.writeBigUInt64LE(BigInt(slice.length), entry + 16);
slice.copy(bytes, headerSize);
expect(readMachoUuidEntries(bytes)).toEqual({
ok: true,
value: [
{ cpuType: 0x01000007, uuid: "44444444-4444-4444-4444-444444444444" },
],
});
});
});

describe("debug companion UUID matching", () => {
const uuid = "A1B2C3D4-E5F6-0789-ABCD-EF0123456789";

Expand Down
63 changes: 39 additions & 24 deletions src/domain/machoDebugCompanion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const LC_UUID = 0x1b;
const FAT_MAGIC_BE = 0xcafebabe;
const FAT_MAGIC_64_BE = 0xcafebabf;
const FAT_MAGIC_LE = 0xbebafeca;
const FAT_MAGIC_64_LE = 0xbebafbfa;
const FAT_MAGIC_64_LE = 0xbfbafeca;
const THIN_LITTLE_MAGICS = new Set([0xcefaedfe, 0xcffaedfe]);
const THIN_BIG_MAGICS = new Set([0xfeedface, 0xfeedfacf]);
const UUID_BYTES = 16;
Expand All @@ -28,8 +28,8 @@ const formatUuid = (raw: Buffer): string => {

/**
* The declared load-command span of a thin Mach-O image, with its byte
* order, so a reader can fetch exactly the bytes the parser walks instead of
* imposing an arbitrary window ceiling.
* order, so a reader can fetch exactly the bytes the parser walks. The span
* is bounded by the reader's region, not by an arbitrary ceiling.
*/
export const machoCommandSpan = (
bytes: Buffer,
Expand All @@ -47,8 +47,7 @@ export const machoCommandSpan = (
const wide = magic === 0xfeedfacf || magic === 0xcffaedfe;
const start = wide ? 32 : 28;
const size = read32(20);
if (size < start || size > 0x8000000)
return err("Mach-O declared load-command span is invalid");
if (size < start) return err("Mach-O declared load-command span is invalid");
return ok({ start, size, little });
};

Expand All @@ -66,39 +65,56 @@ const readUuidsFromThin = (
? (position: number) => bytes.readUInt32LE(position)
: (position: number) => bytes.readUInt32BE(position);
const wide = magic === 0xfeedfacf || magic === 0xcffaedfe;
const commandsOffset = base + (wide ? 32 : 28);
const headerSize = wide ? 32 : 28;
const commandsOffset = base + headerSize;
// Field access requires a complete header; a short prefix is a rejection,
// not a crash.
if (commandsOffset > end)
return err("Mach-O header is truncated before its load commands");
const cpuType = read32(base + 4);
const commandCount = read32(base + 16);
// sizeofcmds excludes the header; its consistency is enforced by exact
// consumption below.
const declaredSize = read32(base + 20);
// Commands live exactly in the declared span; anything after it is not a
// load command no matter what the surrounding bytes look like.
const commandsEnd = Math.min(end, commandsOffset + declaredSize);
let cursor = commandsOffset;
const entries: MachOUuidEntry[] = [];
let consumed = 0;
let observed: string | undefined;
for (let index = 0; index < commandCount; index += 1) {
if (cursor + 8 > end)
if (cursor + 8 > commandsEnd)
return err(`Mach-O load command ${String(index)} is truncated`);
const command = read32(cursor);
const size = read32(cursor + 4);
if (size < 8 || cursor + size > end)
if (size < 8 || cursor + size > commandsEnd)
return err(`Mach-O load command ${String(index)} has an invalid size`);
if (command === LC_UUID) {
if (size < 8 + UUID_BYTES)
return err("LC_UUID load command is truncated");
entries.push({
cpuType,
uuid: formatUuid(bytes.subarray(cursor + 8, cursor + 8 + UUID_BYTES)),
});
// A second LC_UUID in one image is a conflicting identity, not more
// evidence; admission must not pick whichever matches.
if (observed !== undefined)
return err("Mach-O image declares more than one LC_UUID");
observed = formatUuid(
bytes.subarray(cursor + 8, cursor + 8 + UUID_BYTES),
);
}
cursor += size;
consumed += size;
}
return ok(entries);
if (consumed !== declaredSize || cursor !== commandsOffset + declaredSize)
return err(
"Mach-O load commands do not fill the declared load-command span",
);
return ok(observed === undefined ? [] : [{ cpuType, uuid: observed }]);
};

/**
* Read every LC_UUID of a Mach-O image with the declaring image's cputype,
* descending into universal (FAT) containers. Slice order is preserved so a
* caller can attribute each UUID to its architecture; integer accessors
* follow each image's observed byte order. A zero UUID is preserved: it is an
* observed value, not an unknown.
* Read the LC_UUID of a Mach-O image with its declaring cputype, descending
* into universal (FAT) containers of either byte order. Slice order is
* preserved so a caller can attribute each UUID to its architecture; a zero
* UUID is preserved: it is an observed value, not an unknown.
*/
export const readMachoUuidEntries = (
bytes: Buffer,
Expand All @@ -113,10 +129,10 @@ export const readMachoUuidEntries = (
if (fat) {
const wide = magic === FAT_MAGIC_64_BE || magic === FAT_MAGIC_64_LE;
// The architecture table's byte order follows the observed magic.
const read32 =
magic === FAT_MAGIC_BE || magic === FAT_MAGIC_64_BE
? (position: number) => bytes.readUInt32BE(position)
: (position: number) => bytes.readUInt32LE(position);
const big = magic === FAT_MAGIC_BE || magic === FAT_MAGIC_64_BE;
const read32 = big
? (position: number) => bytes.readUInt32BE(position)
: (position: number) => bytes.readUInt32LE(position);
const count = read32(4);
const entrySize = wide ? 32 : 20;
if (count > 128 || 8 + count * entrySize > bytes.length)
Expand All @@ -126,7 +142,6 @@ export const readMachoUuidEntries = (
const entries: MachOUuidEntry[] = [];
for (let index = 0; index < count; index += 1) {
const entry = 8 + index * entrySize;
const big = magic === FAT_MAGIC_BE || magic === FAT_MAGIC_64_BE;
const cpuType = big ? bytes.readInt32BE(entry) : bytes.readInt32LE(entry);
const sliceOffset = wide
? Number(
Expand Down
89 changes: 89 additions & 0 deletions tests/boundary/filesystem/targetDiagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { promisify } from "node:util";
import { describe, expect, it } from "vitest";
import { systemDoctorHost } from "../../../src/application/Doctor.js";
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
import { binaryTargetSummary } from "../../../src/application/binary/BinaryTargetSummary.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { pe } from "../../../src/domain/binaryTarget.fixture.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
Expand Down Expand Up @@ -525,6 +526,13 @@ describe("debug companion fixture admission", () => {
expect(companion?.memberPath).toContain(
join("Contents", "Resources", "DWARF"),
);
expect(binaryTargetSummary(result.value)).toMatchObject({
debug_companion: {
source_path: `${binary}.dSYM`,
uuid: companion?.uuid,
member_sha256: companion?.memberSha256,
},
});
},
);

Expand Down Expand Up @@ -714,3 +722,84 @@ describe("debug companion universal slice selection", () => {
},
);
});

describe("debug companion slice selection", () => {
it.skipIf(!onDarwin)(
"admits only the first slice of a CPU family, not a same-family sibling",
async () => {
const directory = await createTestTempDirectory("rea-dsym-sibling-");
const source = join(directory, "sibling.c");
await writeFile(
source,
[
"#include <stdio.h>",
"__attribute__((noinline)) int twice(int x) { return x * 2; }",
'int main(void) { printf("%d\\n", twice(21)); return 0; }',
"",
].join("\n"),
);
const object = join(directory, "sibling.o");
const binary = join(directory, "sibling");
await execFileAsync("/usr/bin/xcrun", [
"clang",
"-O0",
"-g",
"-c",
source,
"-o",
object,
"-arch",
"x86_64",
"-arch",
"x86_64h",
]);
await execFileAsync("/usr/bin/xcrun", [
"clang",
object,
"-o",
binary,
"-arch",
"x86_64",
"-arch",
"x86_64h",
]);
await execFileAsync("/usr/bin/xcrun", [
"dsymutil",
binary,
"-o",
`${binary}.dSYM`,
]);
const member = `${binary}.dSYM/Contents/Resources/DWARF/sibling`;
const siblingOnly = join(directory, "sibling-only.dSYM");
await execFileAsync("mkdir", [
"-p",
`${siblingOnly}/Contents/Resources/DWARF`,
]);
await execFileAsync("/usr/bin/xcrun", [
"lipo",
"-thin",
"x86_64h",
member,
"-output",
`${siblingOnly}/Contents/Resources/DWARF/sibling`,
]);
// The host-compat selection imports the first x86_64 family slice; a
// companion carrying only the x86_64h sibling UUID must not match.
const result = await parseBinaryTarget(binary, {
dsymPath: siblingOnly,
hostArchitecture: "x64",
});
if (result.ok)
throw new Error("same-family sibling companion was admitted");
const projected = projectAnalysisError(result.error);
expect(projected).toMatchObject({
code: "invalid_request",
details: {
constraint: "debug_companion_rejected",
reason:
"dsym_path contains no Mach-O DWARF member whose LC_UUID matches the selected target slice",
},
});
},
);
});