fix(apple): admit only compatible dyld subcache mappings (#1090)

UUID, architecture, and cache VM offset are one admission decision, so a
matching UUID cannot publish contradictory mappings. A shared-cache trace
hit also requires the mapped bytes to parse as a Mach-O the process can load.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morluto
2026-10-08 22:51:06 +08:00
committed by GitHub
co-authored by Cursor Agent
parent 03bbecd941
commit 4e98543e90
6 changed files with 186 additions and 16 deletions
+33
View File
@@ -540,6 +540,7 @@ const cache = (
].includes(path)
? "mapped"
: "absent",
image: () => Promise.resolve(parsed(slice())),
...overrides,
});
@@ -597,6 +598,38 @@ describe("shared cache resolution", () => {
);
});
it("does not treat mapped bytes as a load until they parse as a compatible Mach-O", async () => {
const root = memoryView({
[MAIN]: executable({
dependencies: [dependency("/usr/lib/libSystem.B.dylib")],
}),
});
const notMachO = await traceDylibLoading(root, {
roots: [MAIN],
sharedCache: cache({
image: () => Promise.resolve({ status: "not-mach-o" }),
}),
});
expect(notMachO.edges[0]?.resolution).toEqual({
status: "undetermined",
image: null,
});
expect(notMachO.coverage).toMatchObject({
status: "partial",
unverified_shared_cache_images: ["/usr/lib/libSystem.B.dylib"],
});
expect(notMachO.images.map(({ path }) => path)).toEqual([MAIN]);
const wrongArchitecture = await traceDylibLoading(root, {
roots: [MAIN],
sharedCache: cache({
image: () => Promise.resolve(parsed(slice({ architecture: "x86_64" }))),
}),
});
expect(wrongArchitecture.edges[0]?.candidates[0]?.outcome).toBe(
"undetermined",
);
});
it("keeps a cache hit conditional after an earlier undeterminable candidate", async () => {
const trace = await traceDylibLoading(
memoryView({