fix(evidence): authenticate identities and retain extraction provenance
Authenticate residual unknown IDs against their immutable identity fields. Permit valid empty ZIP extraction manifests and join firmware child provenance to parent-owned chunk and multi-file reports without inventing missing source ranges. Validated with focused identity, archive, cleanup, and firmware normalization tests. Firmware joins were checked against the pinned Unblob producer; no real Unblob extraction was run.
This commit is contained in:
@@ -117,14 +117,17 @@ describe("Unblob multi-file extraction diagnostics", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it("retains nested MultiFile extraction failures in partial coverage", () => {
|
||||
describe("Unblob task derivation identities", () => {
|
||||
it("joins chunk and MultiFile derivations to their producer blob reports", () => {
|
||||
const outputPath = `${context.outputRoot}/multi`;
|
||||
const chunkPath = `${context.outputRoot}/chunk-child`;
|
||||
const childTask = {
|
||||
path: outputPath,
|
||||
depth: 1,
|
||||
blob_id: "multi-id",
|
||||
is_multi_file: true,
|
||||
is_multi_file: false,
|
||||
};
|
||||
const extractionFailure = {
|
||||
__typename__: "ExtractorDependencyNotFoundReport",
|
||||
@@ -144,10 +147,51 @@ describe("Unblob multi-file extraction diagnostics", () => {
|
||||
[
|
||||
{
|
||||
...parent,
|
||||
reports: parent.reports.filter(
|
||||
(item) => item.__typename__ !== "UnknownChunkReport",
|
||||
),
|
||||
subtasks: [childTask],
|
||||
reports: [
|
||||
...parent.reports.filter(
|
||||
(item) => item.__typename__ !== "UnknownChunkReport",
|
||||
),
|
||||
{
|
||||
__typename__: "ChunkReport",
|
||||
id: "chunk-id",
|
||||
start_offset: 4,
|
||||
end_offset: 10,
|
||||
size: 6,
|
||||
handler_name: "gzip",
|
||||
is_encrypted: false,
|
||||
extraction_reports: [],
|
||||
},
|
||||
multiFileReport,
|
||||
],
|
||||
subtasks: [
|
||||
{
|
||||
path: chunkPath,
|
||||
depth: 1,
|
||||
blob_id: "chunk-id",
|
||||
is_multi_file: false,
|
||||
},
|
||||
childTask,
|
||||
],
|
||||
},
|
||||
{
|
||||
task: {
|
||||
path: chunkPath,
|
||||
depth: 1,
|
||||
blob_id: "chunk-id",
|
||||
is_multi_file: false,
|
||||
},
|
||||
reports: [
|
||||
{
|
||||
__typename__: "StatReport",
|
||||
path: chunkPath,
|
||||
size: 4,
|
||||
is_file: true,
|
||||
is_dir: false,
|
||||
is_link: false,
|
||||
link_target: null,
|
||||
},
|
||||
],
|
||||
subtasks: [],
|
||||
},
|
||||
{
|
||||
task: childTask,
|
||||
@@ -161,7 +205,6 @@ describe("Unblob multi-file extraction diagnostics", () => {
|
||||
is_link: false,
|
||||
link_target: null,
|
||||
},
|
||||
multiFileReport,
|
||||
],
|
||||
subtasks: [],
|
||||
},
|
||||
@@ -170,9 +213,25 @@ describe("Unblob multi-file extraction diagnostics", () => {
|
||||
);
|
||||
|
||||
expect(normalized.coverage).toBe("partial");
|
||||
expect(normalized.derivations).toEqual([
|
||||
{
|
||||
parent_path: "$input",
|
||||
child_path: "$output/chunk-child",
|
||||
provider_blob_id: "chunk-id",
|
||||
handler: "gzip",
|
||||
parent_file_range: { offset: 4, length: 6 },
|
||||
},
|
||||
{
|
||||
parent_path: "$input",
|
||||
child_path: "$output/multi",
|
||||
provider_blob_id: "multi-id",
|
||||
handler: "multipart-firmware",
|
||||
parent_file_range: null,
|
||||
},
|
||||
]);
|
||||
expect(normalized.diagnostics).toEqual([
|
||||
{
|
||||
input_path: "$output/multi",
|
||||
input_path: "$input",
|
||||
stage: "multipart-firmware",
|
||||
missing_dependencies: ["sasquatch"],
|
||||
report: multiFileReport,
|
||||
@@ -181,6 +240,133 @@ describe("Unblob multi-file extraction diagnostics", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Unblob blob identity validation", () => {
|
||||
it("joins reports within each parent, allows missing provenance and rejects local duplicates", () => {
|
||||
const rootChild = {
|
||||
path: `${context.outputRoot}/root-child`,
|
||||
depth: 1,
|
||||
blob_id: "shared-id",
|
||||
is_multi_file: false,
|
||||
};
|
||||
const containerTask = {
|
||||
path: `${context.outputRoot}/container`,
|
||||
depth: 1,
|
||||
blob_id: "container-id",
|
||||
is_multi_file: false,
|
||||
};
|
||||
const nestedChild = {
|
||||
path: `${context.outputRoot}/container/nested-child`,
|
||||
depth: 2,
|
||||
blob_id: "shared-id",
|
||||
is_multi_file: false,
|
||||
};
|
||||
const fileRecord = <T extends { path: string }>(task: T) => ({
|
||||
task,
|
||||
reports: [
|
||||
{
|
||||
__typename__: "StatReport",
|
||||
path: task.path,
|
||||
size: 1,
|
||||
is_file: true,
|
||||
is_dir: false,
|
||||
is_link: false,
|
||||
link_target: null,
|
||||
},
|
||||
],
|
||||
subtasks: [],
|
||||
});
|
||||
const chunk = (
|
||||
id: string,
|
||||
handler: string,
|
||||
start: number,
|
||||
end: number,
|
||||
) => ({
|
||||
__typename__: "ChunkReport",
|
||||
id,
|
||||
start_offset: start,
|
||||
end_offset: end,
|
||||
size: end - start,
|
||||
handler_name: handler,
|
||||
is_encrypted: false,
|
||||
extraction_reports: [],
|
||||
});
|
||||
const base = root();
|
||||
const rootReports = [
|
||||
...base.reports.filter(
|
||||
(report) => report.__typename__ !== "UnknownChunkReport",
|
||||
),
|
||||
chunk("shared-id", "root-handler", 0, 4),
|
||||
chunk("container-id", "container-handler", 4, 10),
|
||||
];
|
||||
const normalized = normalizeUnblobReport(
|
||||
[
|
||||
{
|
||||
...base,
|
||||
reports: rootReports,
|
||||
subtasks: [rootChild, containerTask],
|
||||
},
|
||||
fileRecord(rootChild),
|
||||
{
|
||||
task: containerTask,
|
||||
reports: [
|
||||
{
|
||||
__typename__: "StatReport",
|
||||
path: containerTask.path,
|
||||
size: 10,
|
||||
is_file: true,
|
||||
is_dir: false,
|
||||
is_link: false,
|
||||
link_target: null,
|
||||
},
|
||||
chunk("shared-id", "nested-handler", 2, 5),
|
||||
],
|
||||
subtasks: [nestedChild],
|
||||
},
|
||||
fileRecord(nestedChild),
|
||||
],
|
||||
context,
|
||||
);
|
||||
|
||||
expect(normalized.derivations).toMatchObject([
|
||||
{ handler: "root-handler", parent_file_range: { offset: 0, length: 4 } },
|
||||
{
|
||||
handler: "container-handler",
|
||||
parent_file_range: { offset: 4, length: 6 },
|
||||
},
|
||||
{
|
||||
handler: "nested-handler",
|
||||
parent_file_range: { offset: 2, length: 3 },
|
||||
},
|
||||
]);
|
||||
|
||||
const noOrigin = {
|
||||
...base,
|
||||
reports: base.reports.filter(
|
||||
(report) => report.__typename__ !== "UnknownChunkReport",
|
||||
),
|
||||
subtasks: [rootChild],
|
||||
};
|
||||
expect(
|
||||
normalizeUnblobReport([noOrigin, fileRecord(rootChild)], context)
|
||||
.derivations[0],
|
||||
).toMatchObject({ handler: null, parent_file_range: null });
|
||||
|
||||
expect(() =>
|
||||
normalizeUnblobReport(
|
||||
[
|
||||
{
|
||||
...base,
|
||||
reports: [...rootReports, chunk("shared-id", "duplicate", 10, 12)],
|
||||
subtasks: [rootChild],
|
||||
},
|
||||
fileRecord(rootChild),
|
||||
],
|
||||
context,
|
||||
),
|
||||
).toThrow("Duplicate blob identity in parent task");
|
||||
});
|
||||
});
|
||||
|
||||
describe("firmware producer boundaries", () => {
|
||||
it("rejects unknown tasks outside the owned output and disconnected task graphs", () => {
|
||||
const record = root();
|
||||
|
||||
@@ -57,6 +57,10 @@ const region = z.object({
|
||||
end_offset: integer,
|
||||
size: integer,
|
||||
});
|
||||
type BlobOrigin = {
|
||||
readonly handler: string | null;
|
||||
readonly range: { readonly offset: number; readonly length: number } | null;
|
||||
};
|
||||
const known = new Set([
|
||||
"StatReport",
|
||||
"HashReport",
|
||||
@@ -191,6 +195,20 @@ export const normalizeUnblobReport = (
|
||||
const sizes = new Map<string, number>();
|
||||
const depths: string[] = [];
|
||||
const diagnostics: JsonValue[] = [];
|
||||
const blobOrigins = new Map<string, BlobOrigin>();
|
||||
const addBlobOrigin = (
|
||||
parentPath: string,
|
||||
id: string,
|
||||
origin: BlobOrigin,
|
||||
) => {
|
||||
const key = JSON.stringify([parentPath, id]);
|
||||
if (blobOrigins.has(key))
|
||||
throw new AnalysisOutputError(
|
||||
"extract_firmware",
|
||||
`Duplicate blob identity in parent task: ${parentPath} (${id})`,
|
||||
);
|
||||
blobOrigins.set(key, origin);
|
||||
};
|
||||
const chunks: {
|
||||
input_path: string;
|
||||
provider_id: string;
|
||||
@@ -288,6 +306,10 @@ export const normalizeUnblobReport = (
|
||||
jsonValueSchema.parse(problem),
|
||||
),
|
||||
);
|
||||
addBlobOrigin(path, parsed.id, {
|
||||
handler: detail?.handler_name ?? null,
|
||||
range: { offset: parsed.start_offset, length: parsed.size },
|
||||
});
|
||||
chunks.push({
|
||||
input_path: path,
|
||||
provider_id: parsed.id,
|
||||
@@ -305,6 +327,10 @@ export const normalizeUnblobReport = (
|
||||
}
|
||||
if (item.__typename__ === "MultiFileReport") {
|
||||
const parsed = multiFile.parse(item);
|
||||
addBlobOrigin(path, parsed.id, {
|
||||
handler: parsed.handler_name,
|
||||
range: null,
|
||||
});
|
||||
if (parsed.extraction_reports.length > 0)
|
||||
diagnostics.push(
|
||||
extractionDiagnostic(
|
||||
@@ -319,16 +345,6 @@ export const normalizeUnblobReport = (
|
||||
const recordsByPath = new Map(
|
||||
records.map((record) => [record.task.path, record.task]),
|
||||
);
|
||||
const chunksByOrigin = new Map<string, (typeof chunks)[number]>();
|
||||
for (const item of chunks) {
|
||||
const key = JSON.stringify([item.input_path, item.provider_id]);
|
||||
if (chunksByOrigin.has(key))
|
||||
throw new AnalysisOutputError(
|
||||
"extract_firmware",
|
||||
`Duplicate chunk identity in ${item.input_path}`,
|
||||
);
|
||||
chunksByOrigin.set(key, item);
|
||||
}
|
||||
const derivations = records.flatMap((record) =>
|
||||
record.subtasks.map((child) => {
|
||||
const parentPath = logical(record.task.path);
|
||||
@@ -348,7 +364,7 @@ export const normalizeUnblobReport = (
|
||||
"extract_firmware",
|
||||
`Child task identity disagrees with its analysis: ${childPath}`,
|
||||
);
|
||||
const origin = chunksByOrigin.get(
|
||||
const origin = blobOrigins.get(
|
||||
JSON.stringify([parentPath, child.blob_id]),
|
||||
);
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user