Files
reverse-engineering-anything/tests/boundary/filesystem/keyedArchiveXmlSyntax.test.ts
T
morluto 78fd365bdd refactor(macho): name load-command codes through the shared LC table (#10714)
* refactor(macho): name load-command codes through the shared LC table

* refactor(macho): name version-min and string commands through the shared tables

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure (#10760)

* refactor(parsers): report XML, web artifact and Mach-O failures through ParseFailure

* refactor(xml): type XML parse failures as malformed or unsupported only

* refactor(parsers): catch per-format document and source failure classes (#10794)

* refactor(parsers): report apktool strings and XML plist source failures through ParseFailure

* refactor(apktool): drop the unused ParseFailureError import

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes (#10818)

* refactor(parsers): retire the Mach-O, source-map, NDJSON and managed-graph failure classes

* refactor(plist): report property-list and keyed-archive failures through ParseFailure (#10822)

* refactor(plist): report property-list and keyed-archive failures through ParseFailure

* refactor(kuna): report Kuna document failures through ParseFailure (#10824)

* refactor(kuna): report Kuna document failures through ParseFailure

* test(kuna): pin the limit and malformed facts of Kuna document failures

* refactor(plist): report plist decode budgets through ParseFailure (#10842)

* refactor(plist): report plist decode budgets through ParseFailure

The plist preflight owner throws a ParseFailure limit (plist-decode-bytes) for its byte budget, the shared PlistNestingLimitError for nesting depth, and a malformed failure for a reference cycle, instead of a per-format PropertyListDecodeBudgetFailure whose meaning each caller re-mapped through a fail callback. The fail option, PropertyListDecodeBudgetFailure and interfaceBuilderDecodeBudgetFailure are removed; the parser-format-failure-class baseline reaches zero.

* refactor(plist): report keyed-archive allowances as typed limit failures (#10844)

keyedArchive.ts and decodeKeyedArchiveBytes throw decodeLimit parse failures (keyed-archive-bytes, -object-table-entries, -values-per-object, -reference-edges) and malformed parse failures instead of plain RangeError/TypeError. KeyedArchiveReader no longer classifies every RangeError as a limit: only a limit parse failure or a host stack/capacity limit is one. The unreachable 128-level scan nesting check is removed; projectPlistValue already refuses the archive first.

* test(plist): expect the nesting limit as its ParseFailure carrier

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation (#10895)

* refactor(plist): report plist and NIBArchive input faults through ParseFailure and defects through invariantViolation

* fix(plist): report a cut-short NIB header or plist length record as truncated

* fix(native): project the selected Mach-O's parse failures through the shared owner

nativeMachoSourcePrimary mapped every non-limit ParseFailureError to
AnalysisOutputError, so a malformed or truncated selected Mach-O was
reported as unreadable tool output and an unsupported one lost its
category. It now uses parseFailureAnalysisError like the ELF, Go and
other byte-format providers: malformed and truncated bytes are an
invalid path, unsupported bytes an unsupported target, and a limit
still falls through to its producer's budget.
2026-11-15 18:24:35 +08:00

90 lines
2.8 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { build } from "plist";
import { expect, it } from "vitest";
import { inspectBundleKeyedArchive } from "../../../src/artifacts/apple/KeyedArchiveReader.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const archive = build({
$archiver: "NSKeyedArchiver",
$version: 100000,
$objects: ["$null", "value"],
$top: { root: { UID: 1 } },
});
it.each([
{
name: "unquoted attribute",
xml: archive.replace('version="1.0">', "version=1.0>"),
},
{
name: "undeclared entity",
xml: archive.replace(
"<string>value</string>",
"<string>&unknown;</string>",
),
},
{
name: "forbidden character reference",
xml: archive.replace("<string>value</string>", "<string>&#0;</string>"),
},
{
name: "forbidden literal character",
xml: archive.replace("<string>value</string>", "<string>\u0000</string>"),
},
])("refuses $name before registering archive observations", async ({ xml }) => {
const root = await createTestTempDirectory("rea-keyed-xml-syntax-");
await writeFile(join(root, "Archive.plist"), xml);
await expect(
inspectBundleKeyedArchive({
bundlePath: root,
targetSha256: "a".repeat(64),
parameters: { path: "Archive.plist" },
}),
).rejects.toMatchObject({
reason: "format",
cause: { _tag: "ParseFailureError", kind: "malformed" },
});
});
it("preserves valid Unicode, entity values and original archive identities", async () => {
const root = await createTestTempDirectory("rea-keyed-xml-valid-");
await writeFile(
join(root, "Archive.plist"),
archive.replace("<string>value</string>", "<string>� &amp; &#13;</string>"),
);
const result = await inspectBundleKeyedArchive({
bundlePath: root,
targetSha256: "a".repeat(64),
parameters: { path: "Archive.plist", offset: 1, limit: 1 },
});
expect(result.roots).toEqual({ root: { UID: 1 } });
expect(result.objects).toEqual([
expect.objectContaining({ id: 1, status: "observed", value: "� & \r" }),
]);
expect(result.total_objects).toBe(2);
expect(result.next_offset).toBeNull();
expect(result.truncated).toBe(true);
});
it("reports a dictionary key the archive declares twice", async () => {
const root = await createTestTempDirectory("rea-keyed-xml-repeat-");
await writeFile(
join(root, "Archive.plist"),
archive.replace(
"<key>$version</key>",
"<key>$archiver</key><string>NSKeyedArchiver</string><key>$version</key>",
),
);
const result = await inspectBundleKeyedArchive({
bundlePath: root,
targetSha256: "a".repeat(64),
parameters: { path: "Archive.plist" },
});
expect(result.limitations).toContainEqual(
expect.stringContaining(
'1 dictionary(ies) declare a key more than once ("$archiver")',
),
);
});