fix(artifacts): traverse nested PKG on extract, honor TOC header alg, fatal cpio names

This commit is contained in:
morluto
2026-10-08 16:10:20 +08:00
parent ef0bf91de9
commit b196c5ac8f
3 changed files with 95 additions and 10 deletions
+13 -2
View File
@@ -316,7 +316,8 @@ export class CpioArtifactReader implements ArtifactReader {
),
);
// cpio names require exactly one terminal NUL: a missing terminator or
// an embedded NUL with trailing bytes is malformed.
// an embedded NUL with trailing bytes is malformed. Decode without
// replacement so distinct byte names cannot collapse to one path.
if (
nameBytes.length === 0 ||
nameBytes[nameBytes.length - 1] !== 0 ||
@@ -326,7 +327,17 @@ export class CpioArtifactReader implements ArtifactReader {
"format",
"cpio member name is not NUL-terminated",
);
const raw = nameBytes.toString("utf8", 0, nameBytes.length - 1);
let raw: string;
try {
raw = new TextDecoder("utf-8", { fatal: true }).decode(
nameBytes.subarray(0, nameBytes.length - 1),
);
} catch {
throw new ArtifactReaderFailure(
"format",
"cpio member name is not valid UTF-8",
);
}
if (raw === TRAILER) {
yield* this.#unresolvedLinks();
return;