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): address companion admission review findings
Six review findings on the previous tip:

- Derive admission CPU families from the shared MachoArchitectureSelection
  owner; arm64_32 previously used arm64's cputype (0x0100000c instead of
  0x0200000c), so watchOS targets were reported as UUID-less. A synthetic
  arm64_32 admission regression covers the corrected family.
- Reject dsym_path for trailing-ZIP archive targets instead of silently
  dropping the caller's selection after executable detection fails.
- Restore the misleading.hop WASM routing case dropped from the name matrix.
- State the effective member-size and traversal budgets in their refusal
  reasons, including the fixed-limit notice.
- Return a typed admission rejection when a DWARF member changes while being
  read, so session.open keeps its Result shape instead of throwing.
- Carry the caller's abort reason into admission cancellation errors.
  • Loading branch information
jimpablo committed Oct 28, 2026
commit 0b4ae161cadea0ff1f8feb64dc2b88c93d45db29
11 changes: 10 additions & 1 deletion src/application/BinaryTargetResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,15 @@ const readOpenedBinaryTarget = async (
(await locateTrailingZipArchive(metadata.size, (position, length) =>
readHandleRange(handle, position, length, signal),
)) !== undefined
)
) {
if (dsymPath !== undefined)
return err(
new BinaryTargetError(
path,
"dsym_path applies only to Mach-O executable targets; this target is an archive with a trailing ZIP",
{ constraint: "debug_companion_rejected" },
),
);
return ok({
path,
sourcePath,
Expand All @@ -455,6 +463,7 @@ const readOpenedBinaryTarget = async (
format: zipRootPackageFormat(classificationPath),
artifactSelectedPath: selectedPath,
});
}
const reason =
typeof detected.error === "string"
? detected.error
Expand Down
80 changes: 39 additions & 41 deletions src/application/DebugCompanionAdmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
MachODebugCompanion,
UniversalMachOSlice,
} from "../domain/binaryTargetTypes.js";
import { MACHO_ARCHITECTURE_POLICIES } from "../native/MachoArchitectureSelection.js";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import {
debugCompanionMatches,
Expand Down Expand Up @@ -51,6 +52,10 @@ const resourceLimit = (reason: string): MachOUuidReadFailure => ({
kind: "resource-limit",
reason,
});
const traversalLimit = (): MachOUuidReadFailure =>
resourceLimit(
`the Mach-O UUID traversal exceeds its aggregate read budget of ${String(TRAVERSAL_BUDGET_BYTES >> 20)} MiB across the target and dSYM members; the budget is fixed and cannot be raised at runtime`,
);
const invalidImage = (reason: string): MachOUuidReadFailure => ({
kind: "invalid-image",
reason,
Expand Down Expand Up @@ -79,26 +84,30 @@ const isExpectedAdmissionPathFailure = (cause: unknown): boolean =>
);

/**
* Mach-O cputypes for the provider-neutral CPU families REA admits, including
* the 64-bit flag the ABI sets on x86_64 and arm64. MIPS has no Mach-O
* cputype; a companion can never match it.
* Mach-O cputypes for the provider-neutral CPU families REA admits, taken
* from the shared architecture-selection owner (arm64_32 is 0x0200000c, not
* arm64's 0x0100000c). Architectures without a Mach-O policy — MIPS, 6502,
* RISCV, Hexagon, m68k, PowerPC — have no cputype, so a companion can never
* match them.
*/
const machoFamilyCpuTypes = (
architecture: BinaryArchitecture,
): readonly number[] => {
const policy = MACHO_ARCHITECTURE_POLICIES[architecture];
return policy === undefined ? [] : [policy.cpuType];
};
const CPU_TYPES: Readonly<Record<BinaryArchitecture, readonly number[]>> = {
x86: [0x00000007],
x86_64: [0x01000007],
arm: [0x0000000c],
arm64: [0x0100000c],
mips: [],
// 6502 is admitted only as an explicit raw load, never as a Mach-O family.
"6502": [],
// RISCV has no Mach-O cputype in REA's header families; it is ELF-only.
riscv: [],
// These families have no Mach-O cputype; companions can never match them.
hexagon: [],
m68k: [],
powerpc: [],
// arm64_32 (watchOS) has its own cputype but no distinct dSYM family here.
arm64_32: [0x0100000c],
x86: machoFamilyCpuTypes("x86"),
x86_64: machoFamilyCpuTypes("x86_64"),
arm: machoFamilyCpuTypes("arm"),
arm64: machoFamilyCpuTypes("arm64"),
arm64_32: machoFamilyCpuTypes("arm64_32"),
mips: machoFamilyCpuTypes("mips"),
"6502": machoFamilyCpuTypes("6502"),
riscv: machoFamilyCpuTypes("riscv"),
hexagon: machoFamilyCpuTypes("hexagon"),
m68k: machoFamilyCpuTypes("m68k"),
powerpc: machoFamilyCpuTypes("powerpc"),
};

/** Admitted identity of a caller-selected dSYM companion. */
Expand All @@ -114,7 +123,9 @@ export interface DebugCompanionRejection {

const throwIfCancelled = (signal: AbortSignal | undefined): void => {
if (signal?.aborted === true)
throw new AnalysisCancelledError("resolve_binary_target");
throw new AnalysisCancelledError("resolve_binary_target", {
cause: signal.reason,
});
};
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved

/** Read a bounded window, charging actual I/O and observing cancellation. */
Expand All @@ -127,11 +138,7 @@ const readUuidWindow = async (
): Promise<Result<Buffer, MachOUuidReadFailure>> => {
throwIfCancelled(signal);
if (length > TRAVERSAL_BUDGET_BYTES - ledger.spent)
return err(
resourceLimit(
"the Mach-O traversal exceeds the supported aggregate budget",
),
);
return err(traversalLimit());
const bytes = Buffer.alloc(length);
let filled = 0;
while (filled < length) {
Expand Down Expand Up @@ -176,12 +183,7 @@ const readThinUuidEntry = async (
length - request.offset,
TRAVERSAL_BUDGET_BYTES - ledger.spent,
);
if (windowLength < request.length)
return err(
resourceLimit(
"the Mach-O traversal exceeds the supported aggregate budget",
),
);
if (windowLength < request.length) return err(traversalLimit());
const read = await readUuidWindow(
handle,
offset + request.offset,
Expand Down Expand Up @@ -216,11 +218,7 @@ const chargeTraversal = (
): Result<null, MachOUuidReadFailure> => {
ledger.spent += bytes;
return ledger.spent > TRAVERSAL_BUDGET_BYTES
? err(
resourceLimit(
"the Mach-O traversal exceeds the supported aggregate budget",
),
)
? err(traversalLimit())
: ok(null);
};

Expand Down Expand Up @@ -508,7 +506,7 @@ export const admitDebugCompanion = async (input: {
if (!matched.ok) return ok(null);
if (initial.size > MEMBER_SIZE_LIMIT_BYTES)
return err({
reason: `dsym DWARF member exceeds the supported size: ${memberPath}`,
reason: `dsym DWARF member exceeds the supported size of ${String(MEMBER_SIZE_LIMIT_BYTES >> 30)} GiB: ${memberPath}`,
});

const memberSha256 = await digestOpenHandle(
Expand Down Expand Up @@ -553,11 +551,11 @@ export const admitDebugCompanion = async (input: {
throwIfCancelled(signal);
if (cause instanceof NonRegularFileReadError) continue;
if (cause instanceof RegularFileChangedError)
throw new ArtifactReaderFailure(
"integrity",
"Selected dSYM DWARF member changed while being read",
{ cause },
);
// Expected boundary condition, not a reader fault: report it as a
// typed admission rejection so session.open keeps its Result shape.
return err({
reason: `the dSYM DWARF member changed while being read: ${memberPath}`,
});
const code =
cause instanceof Error && "code" in cause ? cause.code : undefined;
if (
Expand Down
67 changes: 65 additions & 2 deletions tests/boundary/filesystem/targetDiagnostics.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { execFile } from "node:child_process";
import { chmod, readFile, realpath, writeFile } from "node:fs/promises";
import { chmod, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { promisify } from "node:util";
import { describe, expect, it } from "vitest";
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { systemDoctorHost } from "../../../src/application/Doctor.js";
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
import { binaryTargetSummary } from "../../../src/application/binary/BinaryTargetSummary.js";
Expand Down Expand Up @@ -119,7 +120,7 @@ describe("executable format refusal diagnostics", () => {
});

describe("target route diagnostics", () => {
it.each(["module.wasm", "module.bin", "misleading.js"])(
it.each(["module.wasm", "module.bin", "misleading.js", "misleading.hop"])(
"identifies a WASM v1 header in %s without suggesting native provider installation",
async (name) => {
const directory = await createTestTempDirectory("rea-wasm-target-");
Expand Down Expand Up @@ -430,6 +431,33 @@ describe("debug companion admission diagnostics", () => {
},
});
});

it("rejects dsym_path on a trailing-ZIP archive target instead of discarding it", async () => {
const directory = await createTestTempDirectory("rea-dsym-zip-tail-");
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add("a.txt", new TextReader("hello\n"));
const zip = Buffer.from(await writer.close());
const path = join(directory, "selfextractor.tool");
await writeFile(
path,
Buffer.concat([Buffer.from("#!/bin/sh\nexit 0\n"), zip]),
);
const result = await parseBinaryTarget(path, {
dsymPath: join(directory, "selfextractor.dSYM"),
});
if (result.ok)
throw new Error("dsym with a trailing-ZIP archive was admitted");
const projected = projectAnalysisError(result.error);
expect(projected).toMatchObject({
code: "invalid_request",
category: "invalid_input",
details: {
constraint: "debug_companion_rejected",
reason:
"dsym_path applies only to Mach-O executable targets; this target is an archive with a trailing ZIP",
},
});
});
});

describe("debug companion fixture admission", () => {
Expand Down Expand Up @@ -813,6 +841,41 @@ describe("debug companion slice selection", () => {
});
},
);

it("admits a watchOS arm64_32 companion by its own cputype", async () => {
const directory = await createTestTempDirectory("rea-dsym-arm6432-");
const uuid = "0123456789abcdef0123456789abcdef";
// Thin 32-bit Mach-O with LC_UUID; arm64_32 is cputype 0x0200000c, not
// arm64's 0x0100000c, so a family table keyed on the wrong constant would
// report the target as UUID-less and refuse this companion.
const thinArm64_32 = (): Buffer => {
const bytes = Buffer.alloc(28 + 24);
bytes.writeUInt32LE(0xfeedface, 0);
bytes.writeInt32LE(0x0200000c, 4);
bytes.writeUInt32LE(1, 16);
bytes.writeUInt32LE(24, 20);
bytes.writeUInt32LE(0x1b, 28);
bytes.writeUInt32LE(24, 32);
Buffer.from(uuid, "hex").copy(bytes, 36);
return bytes;
};
const target = join(directory, "watch.macho");
await writeFile(target, thinArm64_32());
const bundle = join(directory, "watch.dSYM");
await mkdir(`${bundle}/Contents/Resources/DWARF`, { recursive: true });
await writeFile(`${bundle}/Contents/Resources/DWARF/watch`, thinArm64_32());
const result = await parseBinaryTarget(target, { dsymPath: bundle });
if (!result.ok) {
throw new Error(
`arm64_32 companion was rejected: ${JSON.stringify(result.error)}`,
);
}
expect(result.value).toMatchObject({
format: "mach-o",
architecture: "arm64_32",
debugCompanion: { uuid: "01234567-89AB-CDEF-0123-456789ABCDEF" },
});
});
});

describe("caller-selected and inferred target interpretation", () => {
Expand Down
Loading