mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 22:11:12 +00:00
* fix(resources)!: refuse Windows names ending in a dot or space Node writes files through `\\?\` paths on Windows, so a member named `dir/name.` or `dir/space ` is created literally. Win32 path normalization drops a trailing dot or space when other programs open the path, so `dir\name.` reads the bytes of a sibling `dir\name`, and `dir\space ` cannot be opened. The extraction manifest then records a digest for a path that ordinary tools resolve to different bytes. A Windows output tree now refuses any path segment that ends in a dot or space with DestinationPathUnrepresentableFailure, before creating the path, using the trailing rule isPortablePathSegment already applies. The refusal names the cause and the next step. Reserved device names stay accepted, since Node creates them as ordinary files. Every writer that materializes target-derived names goes through SafeOutputTree (extract_artifact, firmware and UEFI publication, desktop export, environment bundles, recovered JavaScript sources, web script export), so all of them apply the rule. Web script export already moves an unrepresentable URL path to its isolated layout. Fixes #15613 BREAKING CHANGE: On Windows, extract_artifact and other output-tree writers now refuse a path with a segment ending in a dot or space, where they used to write it. To extract the rest of such an archive on Windows, select occurrence_ids that leave those members out, or extract on a non-Windows host. Web script export on Windows writes such URL paths under its isolated layout instead. * ci: run Windows extraction name tests in the curated Windows lane
79 lines
3.4 KiB
TypeScript
79 lines
3.4 KiB
TypeScript
import { lstat, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
|
import { beforeEach, expect, it, vi } from "vitest";
|
|
|
|
import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
|
|
import { artifactExtractionExecutionSchema } from "../../../../src/contracts/artifactToolContracts.js";
|
|
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
|
import { SafeOutputTree } from "../../../../src/resources/SafeOutputTree.js";
|
|
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
|
import { withArtifactClient } from "../../../support/artifactClientScope.js";
|
|
|
|
// The output tree applies its platform's naming rules; select Windows for the
|
|
// destination only, so the refusal is exercised on every host.
|
|
beforeEach(() => {
|
|
const create = SafeOutputTree.create.bind(SafeOutputTree);
|
|
const spy = vi
|
|
.spyOn(SafeOutputTree, "create")
|
|
.mockImplementation((root, _platform, options) =>
|
|
create(root, "win32", options),
|
|
);
|
|
return () => {
|
|
spy.mockRestore();
|
|
};
|
|
});
|
|
|
|
it.each([
|
|
{ member: "dir/name.", decoy: "dir/name" },
|
|
{ member: "dir/space ", decoy: "dir/space" },
|
|
])(
|
|
"refuses Windows extraction of $member, which Win32 paths open as $decoy",
|
|
async ({ member, decoy }) => {
|
|
const root = await createTestTempDirectory("rea-artifact-win32-name-");
|
|
const path = join(root, "fixture.zip");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add(decoy, new TextReader("decoy"));
|
|
await writer.add(member, new TextReader("member"));
|
|
await writeFile(path, await writer.close());
|
|
const parsed = await parseBinaryTarget(path);
|
|
if (!parsed.ok) throw parsed.error;
|
|
|
|
const output = join(root, "output");
|
|
const extracted = await withArtifactClient(parsed.value, (client) =>
|
|
client.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
|
),
|
|
);
|
|
if (extracted.ok) throw new Error(`expected a refusal of ${member}`);
|
|
const detail = `Destination filesystem cannot represent ${JSON.stringify(member)}. Windows paths drop a trailing dot or space from a name, so other programs would open a different file or none. Leave this path out of the selection, or write the output on a non-Windows host.`;
|
|
expect(projectAnalysisError(extracted.error)).toMatchObject({
|
|
message: detail,
|
|
details: { operation: "extract_artifact", reason: "path", detail },
|
|
});
|
|
await expect(lstat(output)).rejects.toMatchObject({ code: "ENOENT" });
|
|
},
|
|
);
|
|
|
|
it("extracts Windows device names as ordinary files", async () => {
|
|
const root = await createTestTempDirectory("rea-artifact-win32-device-");
|
|
const path = join(root, "fixture.zip");
|
|
const writer = new ZipWriter(new Uint8ArrayWriter());
|
|
await writer.add("drivers/aux.c", new TextReader("aux"));
|
|
await writeFile(path, await writer.close());
|
|
const parsed = await parseBinaryTarget(path);
|
|
if (!parsed.ok) throw parsed.error;
|
|
|
|
const output = join(root, "output");
|
|
const extracted = await withArtifactClient(parsed.value, (client) =>
|
|
client.execute(
|
|
"extract_artifact",
|
|
artifactExtractionExecutionSchema.parse({ output_root: output }),
|
|
),
|
|
);
|
|
if (!extracted.ok) throw extracted.error;
|
|
expect((await lstat(join(output, "drivers", "aux.c"))).isFile()).toBe(true);
|
|
});
|