fix(artifacts): extract nested PKG as containers; fatal symlink decoding

This commit is contained in:
morluto
2026-10-08 16:23:58 +08:00
parent da18453d4d
commit 949347a148
2 changed files with 23 additions and 11 deletions
+14 -6
View File
@@ -355,18 +355,26 @@ export class CpioArtifactReader implements ArtifactReader {
if (header.fileSize > MAX_SYMLINK_TARGET_BYTES)
await drain(this.#verified(source, header, raw));
else target = await this.#collect(source, header, raw);
if (path !== undefined)
if (path !== undefined) {
let limitation: string;
if (target === undefined)
limitation = `Symlink target of ${header.fileSize} bytes exceeds ${MAX_SYMLINK_TARGET_BYTES} bytes and was not read.`;
else {
try {
limitation = `Symlink target: ${new TextDecoder("utf-8", { fatal: true }).decode(target)}`;
} catch {
limitation =
"Symlink target is not valid UTF-8 and was not decoded; the archived bytes are preserved only as a byte count.";
}
}
yield entryOf({
path,
kind: "symlink",
key,
header,
limitations: [
target === undefined
? `Symlink target of ${header.fileSize} bytes exceeds ${MAX_SYMLINK_TARGET_BYTES} bytes and was not read.`
: `Symlink target: ${target.toString("utf8")}`,
],
limitations: [limitation],
});
}
return;
}
if (
@@ -156,14 +156,17 @@ const materializeSelection = async ({
const path = normalizeArtifactPath(
frame.prefix === "" ? entry.path : `${frame.prefix}/${entry.path}`,
);
registry.add(path, entry.kind);
// Traverse expanded PKG Payload/Scripts like inventory does, so nested
// members are materialized instead of silently skipped.
if (
// members are materialized instead of silently skipped. An expanded
// member acts as a container: register it as a directory and leave its
// archive bytes to its children, since a file and a directory cannot
// share one output path.
const expandable =
entry.nestedArchive === "gzip-cpio" &&
!entry.encrypted &&
entry.contentUnavailable !== true
) {
entry.contentUnavailable !== true;
registry.add(path, expandable ? "directory" : entry.kind);
if (expandable) {
const parent = frame.reader;
const nested = new CpioArtifactReader((nestedSignal) =>
parent.open(entry, nestedSignal),
@@ -174,6 +177,7 @@ const materializeSelection = async ({
iterator: nested.entries(signal)[Symbol.asyncIterator](),
owned: true,
});
continue;
}
const selectedItem = byPath.get(path);
if (selectedItem === undefined) {