fix(artifacts): trace .app-named files standalone and flag empty FAT tables
- Treat the target as a bundle only when it was opened from an app bundle directory (it carries the bundle's Info.plist); a regular Mach-O file whose name ends in .app is traced from its parent directory. - Classify a FAT header with zero architecture records as malformed, so it stays visible in unclassified roots and coverage. - State that dylib compatibility versions are not compared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
19f01e2610
commit
ef245c0bd0
@@ -246,9 +246,12 @@ class ArtifactClient implements AnalysisClient {
|
||||
"unavailable",
|
||||
"trace_dylib_resolution requires an active Mach-O or .app bundle target",
|
||||
);
|
||||
const bundle = this.target.sourcePath?.toLowerCase().endsWith(".app")
|
||||
? this.target.sourcePath
|
||||
: undefined;
|
||||
// Only a target opened from an app bundle directory carries its Info.plist;
|
||||
// a regular file whose name ends in .app is a standalone image.
|
||||
const bundle =
|
||||
this.target.bundleInfoPlist === undefined
|
||||
? undefined
|
||||
: this.target.sourcePath;
|
||||
const result = await traceDylibResolution({
|
||||
rootPath: bundle ?? dirname(this.target.path),
|
||||
targetPath: this.target.path,
|
||||
|
||||
@@ -237,6 +237,15 @@ describe("Mach-O load command reader failures", () => {
|
||||
}));
|
||||
const facts = await read(fatImage(slices));
|
||||
expect(facts.status === "parsed" && facts.slices).toHaveLength(24);
|
||||
// An empty table is not a Java class file, whose major version is nonzero.
|
||||
for (const magic of [
|
||||
[0xca, 0xfe, 0xba, 0xbe],
|
||||
[0xbf, 0xba, 0xfe, 0xca],
|
||||
])
|
||||
expect(await read(Uint8Array.from([...magic, 0, 0, 0, 0]))).toEqual({
|
||||
status: "malformed",
|
||||
reason: "FAT header declares no architectures",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects string commands too short to hold their string offset", async () => {
|
||||
|
||||
@@ -96,11 +96,14 @@ export const readMachoImage = async (
|
||||
const littleEndian = magic === FAT_CIGAM || magic === FAT_CIGAM_64;
|
||||
const count = view.getUint32(4, littleEndian);
|
||||
const wide = magic === FAT_MAGIC_64 || magic === FAT_CIGAM_64;
|
||||
if (
|
||||
count === 0 ||
|
||||
count > MAX_FAT_ARCHITECTURES ||
|
||||
8 + count * (wide ? 32 : 20) > size
|
||||
)
|
||||
// A Java class file's nonzero major version reads as the count, so an
|
||||
// empty architecture table can only be a malformed universal header.
|
||||
if (count === 0)
|
||||
return {
|
||||
status: "malformed",
|
||||
reason: "FAT header declares no architectures",
|
||||
};
|
||||
if (count > MAX_FAT_ARCHITECTURES || 8 + count * (wide ? 32 : 20) > size)
|
||||
return { status: "not-mach-o" };
|
||||
const table = viewOf(
|
||||
await readExact(readAt, 8, count * (wide ? 32 : 20), "FAT table"),
|
||||
|
||||
@@ -84,4 +84,5 @@ export const DYLIB_RESOLUTION_LIMITATIONS = [
|
||||
"Load order follows dyld's dependents-first traversal in load-command order. An image reached through several chains is resolved once per process, with the rpath stack of the first chain; a later request whose install name matches an already loaded image reuses it.",
|
||||
"@loader_path uses each image's symlink-resolved path within the analyzed root.",
|
||||
"Code-signing checks that can reject a found image, such as library validation and the hardened runtime, are not evaluated.",
|
||||
"Dylib compatibility versions are not compared. Apple's linker documentation describes a load-time rejection when an image's compatibility version is older than the loader requires, but dyld on macOS 26 was observed to load such an image.",
|
||||
];
|
||||
|
||||
@@ -123,3 +123,39 @@ it("rejects targets that are not Mach-O", async () => {
|
||||
expect(JSON.stringify(called.structuredContent)).toContain("unavailable");
|
||||
});
|
||||
});
|
||||
|
||||
it("traces a standalone Mach-O file whose name ends in .app", async () => {
|
||||
const directory = await createTestTempDirectory("rea-dylib-mcp-file-");
|
||||
await writeFile(
|
||||
join(directory, "Tool.app"),
|
||||
machoImage({
|
||||
commands: [dylibCommand(LC.LOAD_DYLIB, "@loader_path/libcore.dylib")],
|
||||
}),
|
||||
);
|
||||
await writeFile(
|
||||
join(directory, "libcore.dylib"),
|
||||
machoImage({ fileType: FILE_TYPE.dylib }),
|
||||
);
|
||||
await withClient(async (client) => {
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: join(directory, "Tool.app") },
|
||||
});
|
||||
expect(opened.isError, JSON.stringify(opened)).not.toBe(true);
|
||||
const called = await client.callTool({
|
||||
name: "trace_dylib_resolution",
|
||||
arguments: {},
|
||||
});
|
||||
expect(called.isError, JSON.stringify(called.structuredContent)).not.toBe(
|
||||
true,
|
||||
);
|
||||
const trace = dylibResolutionResultSchema.parse(
|
||||
structuredResult(called.structuredContent),
|
||||
);
|
||||
expect(trace.edges).toEqual([
|
||||
expect.objectContaining({
|
||||
resolution: { status: "resolved", image: "libcore.dylib" },
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user