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:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user