mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
fix(apple): decode keyed archives that name another archiver
Foundation's NSKeyedUnarchiver decodes a keyed archive whatever its $archiver names. SceneKit writes .scn scenes with SCNKeyedArchiver, so inspect_keyed_archive refused system and third-party scenes such as Audio MIDI Setup's SpeakerRoom.scn as "not an NSKeyedArchiver archive" and pointed the caller at inspect_plist. An archive named NSKeyedArchiver keeps its current handling, including format failures for a damaged table. Another string archiver name is a keyed archive when the plist also has an $objects table and $top roots; without them it stays an ordinary property list with the inspect_plist workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1587b46a9f
commit
11896a6eb1
4 files changed
+57
-6
No files matched your search
@@ -303,7 +303,7 @@ describe("inert keyed archive decoding", () => {
|
||||
offset: 0,
|
||||
limit: 1,
|
||||
}),
|
||||
).toThrow("NSKeyedArchiver");
|
||||
).toThrow("not a keyed archive");
|
||||
expect(() =>
|
||||
decodeKeyedArchiveBytes(Buffer.from(buildBinary(archive)), {
|
||||
root: "missing",
|
||||
|
||||
@@ -181,8 +181,8 @@ const keyedArchiveKindRemediation = (
|
||||
if (kind === "nib-archive")
|
||||
return "Decode compiled NIBArchive files with decode_interface_builder on the app bundle.";
|
||||
return platform === "darwin"
|
||||
? "Inspect an ordinary property list with inspect_plist; inspect_keyed_archive decodes NSKeyedArchiver archives only."
|
||||
: "Select an NSKeyedArchiver archive; inspect_keyed_archive decodes only those. inspect_plist, which reads ordinary property lists, requires a macOS host.";
|
||||
? "Inspect an ordinary property list with inspect_plist; inspect_keyed_archive decodes keyed archives only."
|
||||
: "Select a keyed archive; inspect_keyed_archive decodes only those. inspect_plist, which reads ordinary property lists, requires a macOS host.";
|
||||
};
|
||||
|
||||
interface BundleKeyedArchiveInput {
|
||||
|
||||
@@ -109,13 +109,28 @@ const uid = (
|
||||
return object === undefined ? undefined : plistUidValue(object);
|
||||
};
|
||||
|
||||
/**
|
||||
* Foundation decodes a keyed archive whatever its $archiver names; SceneKit
|
||||
* writes SCNKeyedArchiver. Another name is an archive only with an $objects
|
||||
* table and $top roots, so an ordinary plist keeps the workflow that reads it.
|
||||
*/
|
||||
const isKeyedArchive = (
|
||||
archive: Record<string, JsonValue> | undefined,
|
||||
wrappedScalars: WeakSet<object>,
|
||||
): archive is Record<string, JsonValue> =>
|
||||
archive !== undefined &&
|
||||
(archive.$archiver === "NSKeyedArchiver" ||
|
||||
(typeof archive.$archiver === "string" &&
|
||||
Array.isArray(archive.$objects) &&
|
||||
record(archive.$top, wrappedScalars) !== undefined));
|
||||
|
||||
const archiverMismatch = (
|
||||
archive: Record<string, JsonValue> | undefined,
|
||||
): string => {
|
||||
if (archive === undefined) return "its root is not a dictionary";
|
||||
if (!Object.hasOwn(archive, "$archiver")) return "it has no $archiver key";
|
||||
return typeof archive.$archiver === "string"
|
||||
? `its $archiver is ${JSON.stringify(archive.$archiver)}`
|
||||
? `its $archiver is ${JSON.stringify(archive.$archiver)} without an $objects table and $top roots`
|
||||
: "its $archiver is not a string";
|
||||
};
|
||||
|
||||
@@ -137,9 +152,9 @@ export const projectKeyedArchive = (
|
||||
wrappedScalars.add(scalar),
|
||||
);
|
||||
const archive = record(projected.value, wrappedScalars);
|
||||
if (archive?.$archiver !== "NSKeyedArchiver")
|
||||
if (!isKeyedArchive(archive, wrappedScalars))
|
||||
throw new KeyedArchiveKindError(
|
||||
`Selected property list is not an NSKeyedArchiver archive: ${archiverMismatch(archive)}`,
|
||||
`Selected property list is not a keyed archive: ${archiverMismatch(archive)}`,
|
||||
"property-list",
|
||||
);
|
||||
if (!Array.isArray(archive.$objects))
|
||||
|
||||
@@ -208,6 +208,14 @@ it.each([
|
||||
'its $archiver is "NSArchiver"',
|
||||
"inspect_plist",
|
||||
],
|
||||
[
|
||||
"plist with another archiver and scalar $top",
|
||||
Buffer.from(
|
||||
build({ $archiver: "MyArchiver", $objects: ["$null"], $top: "root" }),
|
||||
),
|
||||
'its $archiver is "MyArchiver" without an $objects table and $top roots',
|
||||
"inspect_plist",
|
||||
],
|
||||
[
|
||||
"compiled NIBArchive",
|
||||
Buffer.concat([Buffer.from("NIBArchive"), Buffer.alloc(40)]),
|
||||
@@ -265,6 +273,34 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("decodes an archive another keyed archiver wrote, as Foundation does", async () => {
|
||||
// SceneKit writes .scn scenes with SCNKeyedArchiver; NSKeyedUnarchiver reads them.
|
||||
const root = await bundle();
|
||||
await writeFile(
|
||||
join(root, "Contents", "Resources", "Scene.scn"),
|
||||
Buffer.from(
|
||||
build({
|
||||
$archiver: "SCNKeyedArchiver",
|
||||
$version: 100000,
|
||||
$objects: ["$null", "value"],
|
||||
$top: { root: { CF$UID: 1 }, other: { CF$UID: 1 } },
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { roots, objects, references, limitations } = await inspect(root, {
|
||||
path: "Contents/Resources/Model.plist",
|
||||
});
|
||||
await expect(
|
||||
inspect(root, { path: "Contents/Resources/Scene.scn" }),
|
||||
).resolves.toMatchObject({
|
||||
archive_path: "Contents/Resources/Scene.scn",
|
||||
roots,
|
||||
objects,
|
||||
references,
|
||||
limitations,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps a damaged NSKeyedArchiver archive a format failure", async () => {
|
||||
const root = await bundle();
|
||||
await writeFile(
|
||||
|
||||
Reference in new issue
Block a user