mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 19:09:21 +00:00
fix(artifacts): keep each extracted file's limitations on that file
extract_artifact copied every selected occurrence's limitations into its own list, prefixed with the path. Extracting VLC's APK listed 862 limitations, 858 of them case-folding collisions between R8-shrunk resource names, and repeated them in the Evidence envelope. Each written file now carries its occurrence's limitations in artifacts[].limitations, absent when it has none, and the extraction's own list counts the files that carry them. The file digest and extraction ID are unchanged: they cover the written files, not their limitations. The same APK's extraction now lists 5 limitations. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
b5d0b49a90
commit
0a80c0bee2
4 files changed
+90
-9
No files matched your search
@@ -310,6 +310,8 @@ interface ExtractedOccurrence {
|
||||
readonly sha256: string;
|
||||
readonly bytes_written: number;
|
||||
readonly created: true;
|
||||
/** The selected occurrence's own limitations; not part of the file digest. */
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
const materializeSelection = async ({
|
||||
@@ -517,6 +519,7 @@ const writeSelectedEntries = async ({
|
||||
sha256: written.sha256,
|
||||
bytes_written: written.bytesWritten,
|
||||
created: true,
|
||||
limitations: selectedItem.occurrence.limitations,
|
||||
});
|
||||
selected.delete(occurrence.occurrence_id);
|
||||
}
|
||||
@@ -578,12 +581,16 @@ const createExtractionResult = (
|
||||
);
|
||||
const extractedContradictions =
|
||||
integrityContradictions.length - (rootContradicted ? 1 : 0);
|
||||
const files = extracted.map(({ limitations: _limitations, ...file }) => file);
|
||||
const limitedFiles = extracted.filter(
|
||||
({ limitations }) => limitations.length > 0,
|
||||
).length;
|
||||
const extractionSemantic = {
|
||||
source_manifest_id: inventory.manifest.manifest_id,
|
||||
selected_occurrence_ids: selected
|
||||
.map(({ occurrence }) => occurrence.occurrence_id)
|
||||
.sort(compareUnicodeCodePoints),
|
||||
files_sha256: digestCanonicalValue(extracted, "Artifact"),
|
||||
files_sha256: digestCanonicalValue(files, "Artifact"),
|
||||
output_root_alias: "$OUTPUT_ROOT" as const,
|
||||
};
|
||||
return artifactExtractionResultSchema.parse({
|
||||
@@ -593,7 +600,13 @@ const createExtractionResult = (
|
||||
extraction_id: `aex_${digestCanonicalValue(extractionSemantic, "Artifact")}`,
|
||||
},
|
||||
output_root: outputRoot,
|
||||
artifacts: extracted,
|
||||
// Each file keeps its occurrence's limitations, so the extraction's own
|
||||
// list does not grow with the archive.
|
||||
artifacts: extracted.map(({ limitations, ...file }) =>
|
||||
limitations.length === 0
|
||||
? file
|
||||
: { ...file, limitations: [...limitations] },
|
||||
),
|
||||
containment_verified: true,
|
||||
cleanup: { attempted: false, verified: true, residual_paths: [] },
|
||||
provenance: [...inventory.provenance, ...materializationProvenance],
|
||||
@@ -604,11 +617,11 @@ const createExtractionResult = (
|
||||
integrity_contradictions: integrityContradictions,
|
||||
limitations: [
|
||||
...traversal.limitations,
|
||||
...selected.flatMap(({ occurrence }) =>
|
||||
occurrence.limitations.map(
|
||||
(limitation) => `${occurrence.logical_path}: ${limitation}`,
|
||||
),
|
||||
),
|
||||
...(limitedFiles === 0
|
||||
? []
|
||||
: [
|
||||
`${String(limitedFiles)} extracted file(s) carry their inventory occurrence's limitations in artifacts[].limitations.`,
|
||||
]),
|
||||
input.occurrenceIds !== undefined
|
||||
? "Only caller-selected regular occurrences exposed by the active artifact reader were materialized; unselected entries and nested archive members were not extracted. Inventory integrity checks still cover the full input."
|
||||
: traversal.status === "complete"
|
||||
|
||||
@@ -337,6 +337,13 @@ const extractedArtifactSchema = z.object({
|
||||
sha256: sha256Schema,
|
||||
bytes_written: z.int().min(0).max(Number.MAX_SAFE_INTEGER),
|
||||
created: z.boolean(),
|
||||
limitations: z
|
||||
.array(z.string())
|
||||
.min(1)
|
||||
.exactOptional()
|
||||
.describe(
|
||||
"The inventory occurrence's own limitations, such as a case-folding collision or a normalized member name; absent when it has none",
|
||||
),
|
||||
});
|
||||
|
||||
/** Path-independent commitment to one selected extraction operation. */
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { artifactExtractionResultSchema } from "../../src/domain/artifactGraph.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"keeps each extracted file's occurrence limitations on that file",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-zip-case-extraction-");
|
||||
const archivePath = join(root, "case.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
// 50 pairs that collide under case folding, as R8-shrunk resources do.
|
||||
for (let index = 0; index < 50; index += 1)
|
||||
for (const name of [
|
||||
`res/-A${String(index)}.xml`,
|
||||
`res/-a${String(index)}.xml`,
|
||||
])
|
||||
await writer.add(name, new TextReader(name));
|
||||
await writeFile(archivePath, await writer.close());
|
||||
const output = join(root, "out");
|
||||
const extracted = await cli.run({
|
||||
arguments: [
|
||||
"extract-artifact",
|
||||
archivePath,
|
||||
"--output-root",
|
||||
output,
|
||||
"--json",
|
||||
],
|
||||
});
|
||||
expect(extracted.exitCode, extracted.stdout + extracted.stderr).toBe(0);
|
||||
const extraction = artifactExtractionResultSchema.parse(
|
||||
parseEvidence(extracted.json).normalized_result,
|
||||
);
|
||||
expect(extraction.artifacts).toHaveLength(100);
|
||||
expect(
|
||||
extraction.artifacts.find(
|
||||
({ relative_path }) => relative_path === "res/-A0.xml",
|
||||
)?.limitations,
|
||||
).toEqual([
|
||||
expect.stringContaining(
|
||||
"Logical path res/-A0.xml collides under English (en-US) Unicode case folding with res/-a0.xml",
|
||||
),
|
||||
]);
|
||||
// The extraction's own list counts them instead of repeating each one.
|
||||
expect(extraction.limitations).toContain(
|
||||
"100 extracted file(s) carry their inventory occurrence's limitations in artifacts[].limitations.",
|
||||
);
|
||||
expect(extraction.limitations.length).toBeLessThan(10);
|
||||
},
|
||||
);
|
||||
@@ -250,9 +250,14 @@ cliTest(
|
||||
scope: "container-entries",
|
||||
status: "complete",
|
||||
});
|
||||
expect(extracted.limitations).toContainEqual(
|
||||
// The reconstructed header belongs to the file it describes.
|
||||
expect(
|
||||
extracted.artifacts.find(
|
||||
({ relative_path }) => relative_path === "PYZ.pyz/app.pyc",
|
||||
)?.limitations,
|
||||
).toContainEqual(
|
||||
expect.stringMatching(
|
||||
/^PYZ\.pyz\/app\.pyc:.*header.*reconstructed.*archive.*magic.*digest.*derived file/iu,
|
||||
/header.*reconstructed.*archive.*magic.*digest.*derived file/iu,
|
||||
),
|
||||
);
|
||||
const expected = new Map([
|
||||
|
||||
Reference in new issue
Block a user