fix(artifacts): read keyed archive dictionaries keyed UID as dictionaries

Foundation encodes `encode(_:forKey: "UID")` as a `$top` dictionary
whose single key is `UID`. The keyed archive projection treated every
one-key `UID`/`CF$UID` dictionary as a reference marker, so that root
became a malformed reference and the real link to its object was lost.

Treat a one-key dictionary as a UID only when its value is a number,
matching the binary decoder's UID shape and Foundation's XML `CF$UID`
rule; otherwise descend into it as an ordinary dictionary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Iwakurakaoru0822
2026-10-06 22:46:16 -07:00
co-authored by Claude Opus 5.5
parent 676959ecb5
commit 35c82b93eb
4 changed files with 87 additions and 11 deletions
+35
View File
@@ -51,6 +51,41 @@ describe("inert keyed archive decoding", () => {
expect.objectContaining({ source: 1, target: 2, status: "resolved" }),
);
});
it.each([
["binary", { UID: 1 }],
["XML", { CF$UID: 1 }],
] as const)(
"resolves a %s root encoded under a UID-named key",
(format, reference) => {
const named = {
...archive,
$objects: ["$null", "payload"],
$top: { UID: reference, CF$UID: reference },
};
const graph = decodeKeyedArchiveBytes(
Buffer.from(format === "binary" ? buildBinary(named) : build(named)),
{ offset: 0, limit: 2 },
);
expect(
graph.references.map(({ source, path, target, status }) => ({
source,
path,
target,
status,
})),
).toEqual([
{ source: null, path: ["CF$UID"], target: 1, status: "resolved" },
{ source: null, path: ["UID"], target: 1, status: "resolved" },
]);
const selected = decodeKeyedArchiveBytes(
Buffer.from(format === "binary" ? buildBinary(named) : build(named)),
{ root: "UID", offset: 0, limit: 2 },
);
expect(selected.references).toEqual([
expect.objectContaining({ path: ["UID"], target: 1 }),
]);
},
);
it("rejects missing roots, malformed plist, and non-keyed archives", () => {
expect(() =>
decodeKeyedArchiveBytes(Buffer.from("bplist00bad"), {