fix(artifacts): keep case-distinct archive names in inventory (#1480)
ZIP member names are case-sensitive. Inventory was folding them with a filesystem case rule, so shrunk APKs never became evidence for the Android application graph. Logical registration now keeps both spellings and records an English Unicode case-folding limitation. Extraction fails only when the destination directory already holds the other spelling. Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
@@ -9,6 +9,8 @@ import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js
|
||||
import { createDirectAnalysis } from "../../../../src/composition/directAnalysis.js";
|
||||
import {
|
||||
ArtifactPathRegistry,
|
||||
destinationCaseCollisionMessage,
|
||||
ENGLISH_UNICODE_CASE_INVENTORY_LIMITATION,
|
||||
normalizeArtifactPath,
|
||||
} from "../../../../src/artifacts/ArtifactPaths.js";
|
||||
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
||||
@@ -95,17 +97,8 @@ describe("artifact archive safety", () => {
|
||||
});
|
||||
const registry = new ArtifactPathRegistry();
|
||||
registry.add("A.js", "file");
|
||||
let collisionError: unknown;
|
||||
try {
|
||||
registry.add("a.js", "file");
|
||||
} catch (error: unknown) {
|
||||
collisionError = error;
|
||||
}
|
||||
expect(collisionError).toBeInstanceOf(ArtifactReaderFailure);
|
||||
expect(collisionError).toMatchObject({
|
||||
reason: "path",
|
||||
message: "Artifact path collision: a.js differs only in case from A.js",
|
||||
});
|
||||
expect(() => registry.add("a.js", "file")).not.toThrow();
|
||||
expect(() => registry.add("A.js", "file")).toThrow(ArtifactReaderFailure);
|
||||
|
||||
for (const [filePath, childPath] of [
|
||||
["Foo", "foo/bar"],
|
||||
@@ -113,11 +106,15 @@ describe("artifact archive safety", () => {
|
||||
] as const) {
|
||||
const casePrefixRegistry = new ArtifactPathRegistry();
|
||||
casePrefixRegistry.add(filePath, "file");
|
||||
expect(() => casePrefixRegistry.add(childPath, "file")).toThrow(
|
||||
ArtifactReaderFailure,
|
||||
);
|
||||
expect(() => casePrefixRegistry.add(childPath, "file")).not.toThrow();
|
||||
}
|
||||
|
||||
const exactPrefixRegistry = new ArtifactPathRegistry();
|
||||
exactPrefixRegistry.add("Foo", "file");
|
||||
expect(() => exactPrefixRegistry.add("Foo/bar", "file")).toThrow(
|
||||
ArtifactReaderFailure,
|
||||
);
|
||||
|
||||
const sameDirectoryRegistry = new ArtifactPathRegistry();
|
||||
sameDirectoryRegistry.add("Foo/one.js", "file");
|
||||
expect(() => sameDirectoryRegistry.add("Foo/two.js", "file")).not.toThrow();
|
||||
@@ -126,7 +123,50 @@ describe("artifact archive safety", () => {
|
||||
caseVariantDirectoryRegistry.add("Foo/one.js", "file");
|
||||
expect(() =>
|
||||
caseVariantDirectoryRegistry.add("foo/two.js", "file"),
|
||||
).toThrow(ArtifactReaderFailure);
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it("names a destination case collision from the directory listing", () => {
|
||||
expect(
|
||||
destinationCaseCollisionMessage("res/2f.xml", ["2F.xml", "other.xml"]),
|
||||
).toBe(
|
||||
"Destination filesystem cannot store both res/2f.xml and res/2F.xml; inventory retains both logical names.",
|
||||
);
|
||||
expect(
|
||||
destinationCaseCollisionMessage("res/2f.xml", ["2f.xml", "2F.xml"]),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("extracts logical names that differ only in case", async () => {
|
||||
const root = await createTestTempDirectory("rea-case-distinct-zip-");
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("Main.js", new TextReader("upper"));
|
||||
await writer.add("main.js", new TextReader("lower"));
|
||||
await writeFile(path, await writer.close());
|
||||
const parsed = await parseBinaryTarget(path);
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) return;
|
||||
const result = await inventory(parsed.value);
|
||||
expect(result.limitations).toContain(
|
||||
ENGLISH_UNICODE_CASE_INVENTORY_LIMITATION,
|
||||
);
|
||||
expect(
|
||||
result.occurrences
|
||||
.filter(({ logical_path }) => logical_path !== ".")
|
||||
.map(({ logical_path }) => logical_path)
|
||||
.sort(),
|
||||
).toEqual(["Main.js", "main.js"]);
|
||||
const output = join(root, "output");
|
||||
const extracted = await new ArtifactProvider(process.env)
|
||||
.createClient(parsed.value)
|
||||
.execute(
|
||||
"extract_artifact",
|
||||
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
||||
);
|
||||
expect(extracted.ok).toBe(true);
|
||||
expect(await readFile(join(output, "Main.js"), "utf8")).toBe("upper");
|
||||
expect(await readFile(join(output, "main.js"), "utf8")).toBe("lower");
|
||||
});
|
||||
});
|
||||
const inventory = async (targetValue: BinaryTarget) => {
|
||||
|
||||
@@ -6,30 +6,73 @@ import { writeOrderedZip } from "../../../fixtures/artifactEntryOrder.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
||||
import {
|
||||
destinationCaseCollisionMessage,
|
||||
ENGLISH_UNICODE_CASE_INVENTORY_LIMITATION,
|
||||
} from "../../../../src/artifacts/ArtifactPaths.js";
|
||||
import { ArtifactProvider } from "../../../../src/artifacts/ArtifactProvider.js";
|
||||
import { artifactInventoryResultSchema } from "../../../../src/domain/artifactGraph.js";
|
||||
import { ArtifactOperationError } from "../../../../src/domain/artifactOperationError.js";
|
||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||
|
||||
it.each([
|
||||
[
|
||||
["Main.js", "main.js"],
|
||||
"Artifact path collision: main.js differs only in case from Main.js",
|
||||
],
|
||||
[["a\\b.js"], 'Artifact path is absolute or unsafe: "a\\\\b.js"'],
|
||||
] as const)(
|
||||
"reports the failed path constraint for %j",
|
||||
async (entries, detail) => {
|
||||
const root = await createTestTempDirectory("rea-artifact-detail-");
|
||||
const path = join(root, "fixture.zip");
|
||||
await writeOrderedZip(path, entries);
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw new Error("expected a ZIP target");
|
||||
const result = await new ArtifactProvider(process.env)
|
||||
.createClient(target.value)
|
||||
.execute("inventory_artifact", {});
|
||||
if (result.ok) throw new Error("expected the path constraint to fail");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "artifact_operation_failed",
|
||||
details: { operation: "inventory_artifact", reason: "path", detail },
|
||||
});
|
||||
},
|
||||
);
|
||||
it("keeps logical names that differ only in case and records the limitation", async () => {
|
||||
const root = await createTestTempDirectory("rea-artifact-detail-");
|
||||
const path = join(root, "fixture.zip");
|
||||
await writeOrderedZip(path, ["Main.js", "main.js"]);
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw new Error("expected a ZIP target");
|
||||
const result = await new ArtifactProvider(process.env)
|
||||
.createClient(target.value)
|
||||
.execute("inventory_artifact", {});
|
||||
if (!result.ok) throw result.error;
|
||||
const inventory = artifactInventoryResultSchema.parse(result.value.result);
|
||||
expect(inventory.occurrences.map(({ logical_path }) => logical_path)).toEqual(
|
||||
expect.arrayContaining(["Main.js", "main.js"]),
|
||||
);
|
||||
expect(inventory.limitations).toContain(
|
||||
ENGLISH_UNICODE_CASE_INVENTORY_LIMITATION,
|
||||
);
|
||||
for (const logicalPath of ["Main.js", "main.js"]) {
|
||||
expect(
|
||||
inventory.occurrences
|
||||
.find((occurrence) => occurrence.logical_path === logicalPath)
|
||||
?.limitations.join("\n"),
|
||||
).toContain("English (en-US) Unicode case folding");
|
||||
}
|
||||
});
|
||||
|
||||
it("reports an unsafe path as a hostile artifact path", async () => {
|
||||
const root = await createTestTempDirectory("rea-artifact-detail-");
|
||||
const path = join(root, "fixture.zip");
|
||||
await writeOrderedZip(path, ["a\\b.js"]);
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw new Error("expected a ZIP target");
|
||||
const result = await new ArtifactProvider(process.env)
|
||||
.createClient(target.value)
|
||||
.execute("inventory_artifact", {});
|
||||
if (result.ok) throw new Error("expected the path constraint to fail");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "artifact_operation_failed",
|
||||
message:
|
||||
"Artifact contains an unsafe internal path. Inspect the reported path and correct the artifact before retrying.",
|
||||
details: {
|
||||
operation: "inventory_artifact",
|
||||
reason: "path",
|
||||
detail: 'Artifact path is absolute or unsafe: "a\\\\b.js"',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a destination case collision as the user-facing path message", () => {
|
||||
const detail = destinationCaseCollisionMessage("res/2f.xml", ["2F.xml"]);
|
||||
expect(detail).toEqual(expect.any(String));
|
||||
if (detail === undefined) return;
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new ArtifactOperationError("extract_artifact", "path", undefined, detail),
|
||||
),
|
||||
).toMatchObject({
|
||||
message: detail,
|
||||
details: { reason: "path", detail },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,6 +86,12 @@ describe("Android application projection", () => {
|
||||
expect(left.bridge_candidates).toEqual([
|
||||
expect.objectContaining({ basis: "react-native-convention" }),
|
||||
]);
|
||||
expect(left.limitations).toEqual(
|
||||
expect.arrayContaining([
|
||||
"A bridge basis is inferred from the native path and is repeated for every managed component.",
|
||||
"ZIP inventory cannot see the APK Signing Block, so an empty signing array does not mean the APK is unsigned.",
|
||||
]),
|
||||
);
|
||||
expect(JSON.stringify(left)).not.toContain("opaque signing");
|
||||
});
|
||||
|
||||
@@ -146,6 +152,45 @@ describe("Android application projection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("case-distinct APK resource names", () => {
|
||||
it("inventories and projects an APK whose resource names differ only in case", async () => {
|
||||
const root = await createTestTempDirectory("rea-android-case-");
|
||||
const path = join(root, "Shrunk.apk");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add(
|
||||
"AndroidManifest.xml",
|
||||
new Uint8ArrayReader(Uint8Array.from([3, 0, 8, 0])),
|
||||
);
|
||||
await writer.add(
|
||||
"classes.dex",
|
||||
new Uint8ArrayReader(
|
||||
Uint8Array.from([0x64, 0x65, 0x78, 0x0a, 0x30, 0x33, 0x35, 0]),
|
||||
),
|
||||
);
|
||||
await writer.add("res/2F.xml", new TextReader("upper"));
|
||||
await writer.add("res/2f.xml", new TextReader("lower"));
|
||||
await writeFile(path, await writer.close());
|
||||
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const result = projectAndroidApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
});
|
||||
const projection = androidApplicationProjectionResultSchema.parse(
|
||||
requireSuccessfulProjection(result).normalized_result,
|
||||
);
|
||||
expect(projection.root_format).toBe("apk");
|
||||
expect(projection.components.manifests).toHaveLength(1);
|
||||
expect(projection.components.dex).toHaveLength(1);
|
||||
expect(JSON.stringify(inventory)).toContain("res/2F.xml");
|
||||
expect(JSON.stringify(inventory)).toContain("res/2f.xml");
|
||||
expect(JSON.stringify(inventory)).toContain(
|
||||
"English (en-US) Unicode case folding",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Android bridge candidate coverage", () => {
|
||||
it("returns every component and bridge candidate from the inventory", async () => {
|
||||
const root = await createTestTempDirectory("rea-android-complete-");
|
||||
|
||||
Reference in New Issue
Block a user