Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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(apple): bind standalone joins to admitted source identity
  • Loading branch information
morluto committed Nov 9, 2026
commit 5e87f63ad955b8e6c2687f78357ca74943c2645d
3 changes: 3 additions & 0 deletions docs/apple-ips.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ rea inspect-apple-ips /absolute/path/to/report.ips \
--join-path /absolute/path/to/App.app/Contents/MacOS/App --json
```

Shared-cache image sources `S` and `C` remain unjoined: UUID agreement does not
establish that a standalone image has the cached layout.

For a FAT container every slice is examined. An image joins only when exactly
one slice has that UUID **and** an architecture that agrees with the report's
`arch`; `arm64` and `arm64e` stay distinct, and an all-zero UUID never joins. A
Expand Down
50 changes: 50 additions & 0 deletions src/application/binaryDiagnostics/AppleIpsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,53 @@ it.each([
if (!result.ok) expect(result.error._tag).toBe("AnalysisOutputError");
},
);

it.each([
[undefined, 16, false],
["/artifacts/other.bin", 16, false],
["/artifacts/selected.bin", 15, false],
["/artifacts/selected.bin", 16, true],
] as const)(
"binds returned join identity to selected path %s and allowance %s",
async (selected, maximum, accepted) => {
const joined: AppleIps = {
...report,
join: {
status: "unreadable",
path: "/artifacts/selected.bin",
sha256: "b".repeat(64),
bytes: 16,
reason: "Not a Mach-O image",
},
};
const result = await new AppleIpsService({
identity,
inspect: async () => ok(joined),
}).inspect({
path: report.artifact.path,
...(selected === undefined ? {} : { join_path: selected }),
max_join_bytes: maximum,
});
expect(result.ok).toBe(accepted);
if (result.ok)
expect(result.value.locations).toEqual([
{ kind: "artifact-path", path: report.artifact.path },
{ kind: "artifact-path", path: "/artifacts/selected.bin" },
]);
else expect(result.error._tag).toBe("AnalysisOutputError");
},
);

it("rejects a provider's omitted join after explicit selection", async () => {
const result = await new AppleIpsService({
identity,
inspect: async () => ok(report),
}).inspect({
path: report.artifact.path,
join_path: "/artifacts/selected.bin",
});
expect(result).toMatchObject({
ok: false,
error: { _tag: "AnalysisOutputError" },
});
});
14 changes: 13 additions & 1 deletion src/application/binaryDiagnostics/AppleIpsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ export class AppleIpsService {
result: value,
confidence: "observed",
limitations: value.limitations,
locations: [{ kind: "artifact-path", path: value.artifact.path }],
locations: [
{ kind: "artifact-path", path: value.artifact.path },
...(value.join === null || value.join.path === value.artifact.path
? []
: [{ kind: "artifact-path" as const, path: value.join.path }]),
],
},
),
options?.signal,
Expand All @@ -76,6 +81,11 @@ const validReport = (
input: InspectAppleIpsInputLike,
): boolean => {
if (
(input.join_path === undefined
? report.join !== null
: report.join === null ||
report.join.path !== input.join_path ||
report.join.bytes > input.max_join_bytes) ||
report.artifact.bytes > input.max_file_bytes ||
report.coverage.threads > input.max_threads ||
report.coverage.frames > input.max_frames ||
Expand Down Expand Up @@ -112,6 +122,8 @@ const validReport = (
};

type InspectAppleIpsInputLike = {
readonly join_path?: string | undefined;
readonly max_join_bytes: number;
readonly max_file_bytes: number;
readonly max_threads: number;
readonly max_frames: number;
Expand Down
6 changes: 6 additions & 0 deletions src/native/apple/AppleIpsMachOJoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ export const resolveAppleIpsJoin = async (
const matchedImage = new Map<number, AppleIpsJoinDigest>();
const rejectedImage = new Map<number, string>();
for (const image of report.images) {
if (image.source === "S" || image.source === "C") {
const reason = `image ${String(image.index)} is shared-cache-backed; standalone-image join applicability is unknown`;
limitations.push(reason);
rejectedImage.set(image.index, reason);
continue;
}
const recordedArch = image.arch ?? "";
if (image.uuid === null || recordedArch === "") continue;
Comment thread
morluto marked this conversation as resolved.
Resolved
const candidates = parsed.slices.filter(
Expand Down
46 changes: 46 additions & 0 deletions tests/boundary/filesystem/appleIpsJoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ const inspectWithJoin = async (
join_path: joinPath,
});
if (!result.ok) throw result.error;
expect(result.value.locations).toEqual([
{ kind: "artifact-path", path: ipsPath },
{ kind: "artifact-path", path: joinPath },
]);
const output = result.value.normalized_result as unknown as {
readonly join: {
readonly status: string;
Expand Down Expand Up @@ -484,3 +488,45 @@ it("retains architecture diagnostics once per image instead of expanding them pe
await service.close();
}
});

it.each(["S", "C"])(
"leaves shared-cache image source %s unjoined despite matching UUID and CPU",
async (source) => {
const root = await createTestTempDirectory("rea-ips-cache-source-");
const path = join(root, "report.ips");
await writeFile(
path,
appleIpsBytes()
.toString()
.replace('"source": "P"', `"source": "${source}"`),
);
const joinPath = join(root, "join.bin");
await writeFile(
joinPath,
machoSlice({ cpu: ARM64, uuid: FIXTURE_UUID, textVmaddr: 0x100000000n }),
);
const service = createAppleIpsService();
try {
const result = await service.inspect({ path, join_path: joinPath });
if (!result.ok) throw result.error;
const parsed = appleIpsSchema.parse(result.value.normalized_result);
expect(parsed.join).toMatchObject({
status: "selected",
image_matches: [],
frames: expect.arrayContaining([
expect.objectContaining({
thread_index: 0,
frame_index: 0,
status: "unjoined",
}),
]),
});
if (parsed.join?.status === "selected")
expect(parsed.join.limitations.join(" ")).toContain(
"shared-cache-backed",
);
} finally {
await service.close();
}
},
);
Loading