fix(artifacts): decode flat keyed-archive NIBs with data and shared references

decode_interface_builder failed on every flat (keyed-archive) NIB that
holds plist data or dates. Archived colors keep their components as
data, so this covers nearly every AppKit NIB: XLD.app decoded 0 of 64.
The decoded Uint8Array and Date values failed JSON validation. They now
use the shared plist projection, which keeps them as explicit
$plist_type values.

Decoding those archives exposed a second failure. The keyed-archive
parser inlined every UID reference up to 16 levels for every object, so
an archive whose views reference their window, superview, and next key
view expanded exponentially. A 9 KB NIB took 3 s, and a 158 KB
MainMenu.nib did not finish. A reference now resolves to its string, or
to a stub naming the referenced object's archive UID, authored ID, and
class. The hierarchy walk visits each object once. The parser also reads
XML CF$UID references and treats UID 0 as nil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-07 08:10:25 +00:00
co-authored by Claude Opus 5.5
parent faaee693d5
commit 2a4667bb79
4 changed files with 256 additions and 57 deletions
+10 -5
View File
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
import { parseBinary } from "plist";
import { DirectoryArtifactReader } from "../artifacts/DirectoryArtifactReader.js";
import { projectPlistValue } from "../domain/plistValue.js";
import { parseXmlPropertyList } from "../domain/propertyListKeys.js";
import {
decodeNibArchive,
@@ -370,10 +371,14 @@ const readEntry = async (
return Buffer.concat(chunks, length);
};
const decodePlist = (bytes: Buffer): JsonValue => {
const parsed =
/**
* Decode a keyed-archive plist. Data and dates, such as an archived color's
* `NSWhite` bytes, become explicit `$plist_type` values rather than failing
* JSON validation.
*/
const decodePlist = (bytes: Buffer): JsonValue =>
projectPlistValue(
bytes.subarray(0, 8).toString("ascii") === "bplist00"
? parseBinary(bytes)
: parseXmlPropertyList(bytes.toString("utf8")).value;
return jsonValueSchema.parse(parsed);
};
: parseXmlPropertyList(bytes.toString("utf8")).value,
).value;