fix(artifacts): propagate conditional loads and bind digests to parsed images
- Edges below a conditional fallback now carry loader_conditional, reuse of a conditional image by install name is conditional, and their findings say they apply only if that image loads. - Hash each traced image only if it is still the file whose headers were parsed (device, inode, size and change times), before and after hashing. - Resolve explicit roots segment by segment, so a root below a symlinked directory that points outside the analyzed root is rejected. - Require a complete 16-byte LC_CODE_SIGNATURE command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9049620dfe
commit
5e334a0e12
@@ -116,6 +116,11 @@ const edgeSchema = z.strictObject({
|
||||
image: z.string().nullable(),
|
||||
}),
|
||||
install_name_matches: z.boolean().nullable(),
|
||||
/**
|
||||
* The loader was reached through a conditional edge, so it might not load;
|
||||
* this edge describes what happens only if it does.
|
||||
*/
|
||||
loader_conditional: z.boolean(),
|
||||
});
|
||||
|
||||
const findingSchema = z.strictObject({
|
||||
@@ -179,6 +184,8 @@ interface LoadedImage {
|
||||
readonly slice: MachoSlice;
|
||||
/** Images from the process root to this image; the rpath stack, outermost first. */
|
||||
readonly chain: readonly string[];
|
||||
/** Some edge on the chain was conditional: an unknown earlier candidate may load instead. */
|
||||
readonly conditional: boolean;
|
||||
}
|
||||
|
||||
interface ProcessContext {
|
||||
@@ -307,7 +314,8 @@ const resolveDependency = async (
|
||||
loader: string,
|
||||
context: ProcessContext,
|
||||
): Promise<Edge> => {
|
||||
const chain = context.loaded.get(loader)?.chain ?? [loader];
|
||||
const current = context.loaded.get(loader);
|
||||
const chain = current?.chain ?? [loader];
|
||||
const loaded = context.byInstallName.get(dependency.install_name);
|
||||
const candidates: Candidate[] = [];
|
||||
if (loaded !== undefined)
|
||||
@@ -326,7 +334,14 @@ const resolveDependency = async (
|
||||
// dyld stops at the first loadable candidate.
|
||||
if (candidate.outcome === "resolved") break;
|
||||
}
|
||||
const resolved = resolution(candidates);
|
||||
const searched = resolution(candidates);
|
||||
// Reusing an image that itself loads only conditionally is conditional too.
|
||||
const resolved: Edge["resolution"] =
|
||||
loaded !== undefined &&
|
||||
context.loaded.get(loaded)?.conditional === true &&
|
||||
searched.status === "resolved"
|
||||
? { ...searched, status: "conditional" }
|
||||
: searched;
|
||||
const image =
|
||||
resolved.image === null ? undefined : context.images.get(resolved.image);
|
||||
const slice =
|
||||
@@ -345,6 +360,7 @@ const resolveDependency = async (
|
||||
slice === undefined || slice.install_name === null
|
||||
? null
|
||||
: slice.install_name === dependency.install_name,
|
||||
loader_conditional: current?.conditional ?? false,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -358,7 +374,11 @@ const traceProcess = async (
|
||||
signal?: AbortSignal,
|
||||
): Promise<Edge[]> => {
|
||||
const edges: Edge[] = [];
|
||||
context.loaded.set(context.root, { slice: rootSlice, chain: [context.root] });
|
||||
context.loaded.set(context.root, {
|
||||
slice: rootSlice,
|
||||
chain: [context.root],
|
||||
conditional: false,
|
||||
});
|
||||
if (rootSlice.install_name !== null)
|
||||
context.byInstallName.set(rootSlice.install_name, context.root);
|
||||
const pending = [context.root];
|
||||
@@ -381,7 +401,13 @@ const traceProcess = async (
|
||||
? compatibleSlice(facts.slices, context.architecture)
|
||||
: undefined;
|
||||
if (slice === undefined) continue;
|
||||
context.loaded.set(image, { slice, chain: [...current.chain, image] });
|
||||
context.loaded.set(image, {
|
||||
slice,
|
||||
chain: [...current.chain, image],
|
||||
// dyld may load an unknown earlier candidate instead of this fallback.
|
||||
conditional:
|
||||
current.conditional || edge.resolution.status === "conditional",
|
||||
});
|
||||
if (
|
||||
slice.install_name !== null &&
|
||||
!context.byInstallName.has(slice.install_name)
|
||||
|
||||
Reference in New Issue
Block a user