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"),
|
||||
|
||||
Reference in New Issue
Block a user