fix(artifacts): read ASCII control bytes in legacy ZIP names as ASCII (#2365)
* fix(artifacts): read ASCII control bytes in legacy ZIP names as ASCII ZIP names without the UTF-8 flag were decoded with zip.js's CP437 table, which maps bytes 0x01-0x1F and 0x7F to IBM PC display glyphs. A folder zipped on macOS with a custom icon therefore listed and extracted `Folder/Icon\r` as `Folder/Icon♪`, a name that is not in the archive and differs from REA's directory inventory of the same folder. Tabs became `○` and DEL became `⌂`. Decode legacy names in REA's existing decodeText hook with the Unicode CP437 mapping that Python's zipfile also uses: bytes below 0x80 as ASCII, and the upper half with the same table zip.js uses. Windows file names cannot contain U+0001-U+001F, so a Windows extraction destination now refuses such a path with a typed path failure before creating anything, as it already does for ':'. * test(artifacts): check extracted legacy ZIP control names on disk The control-name cases checked only the logical path that inventory reports. Extraction writes through SafeOutputTree, so a change that renamed the extracted files would still pass those cases. Extract `Icon\r` and `é\t\u007F.a`, then compare the reported relative_path, the directory listing, and the file contents. The new cases skip on Windows, which refuses these names. safeOutputTree.test.ts covers that refusal.
This commit is contained in:
@@ -489,4 +489,28 @@ describe("safe artifact output Windows stream paths", () => {
|
||||
await expect(access(output)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readdir(parent)).toEqual([]);
|
||||
});
|
||||
|
||||
it.each(["Folder/Icon\r", "Fold\ter/file.txt"])(
|
||||
"refuses Windows control characters before creating %j",
|
||||
async (path) => {
|
||||
const parent = await createTestTempDirectory("rea-safe-output-control-");
|
||||
const output = join(parent, "published");
|
||||
const tree = await SafeOutputTree.create(output, "win32");
|
||||
const bytes = Buffer.from("regular file content");
|
||||
await expect(
|
||||
tree.write(path, Readable.from(bytes), {
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.byteLength,
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
reason: "path",
|
||||
message: `Windows destination cannot materialize artifact path: ${JSON.stringify(path)}; Windows names cannot contain U+0001-U+001F.`,
|
||||
});
|
||||
expect(await readdir(output)).toEqual([]);
|
||||
expect(await tree.rollback()).toEqual({
|
||||
status: "complete",
|
||||
residualPaths: [],
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user