mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
* 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.
188 lines
6.6 KiB
TypeScript
188 lines
6.6 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { parseOpenStep } from "plist";
|
|
|
|
import {
|
|
decodeOpenStepPropertyList,
|
|
startsOpenStepPropertyList,
|
|
type OpenStepPropertyListCode,
|
|
} from "./propertyListOpenStep.js";
|
|
|
|
it.each([
|
|
"{ numeric = (42, -2.5, 0x10, YES); path = /a/b:c$; }",
|
|
"{ bytes = (<ffzz0>, <0>, <a b c d>, <>); }",
|
|
'/* header */ ("//text", "/*text*/", /* before */ value, // after\n)',
|
|
"{ first = x second = y; third = (a, b,); }",
|
|
"{ (one, two) = array; { nested = key; } = object; <01ff> = data; }",
|
|
"{} /* unterminated",
|
|
"() ((((((((((",
|
|
])("preserves pinned lexical and container values for %s", (text) => {
|
|
expect(decodeOpenStepPropertyList(text)).toEqual(parseOpenStep(text));
|
|
});
|
|
|
|
const syntaxFailure = (read: () => unknown): Error => {
|
|
try {
|
|
read();
|
|
} catch (cause) {
|
|
if (cause instanceof Error) return cause;
|
|
throw cause;
|
|
}
|
|
throw new Error("Expected syntax failure");
|
|
};
|
|
|
|
const containerRefusal = (
|
|
code: OpenStepPropertyListCode,
|
|
position: number,
|
|
) => ({ code, position });
|
|
|
|
const containerRefusals = [
|
|
["(}", containerRefusal("unexpected_character", 1)],
|
|
["{)", containerRefusal("unexpected_character", 1)],
|
|
["(@", containerRefusal("unexpected_character", 1)],
|
|
["{key @", containerRefusal("expected_equals", 5)],
|
|
["(x @", containerRefusal("expected_separator", 3)],
|
|
[
|
|
"(x ",
|
|
containerRefusal("unterminated_array", 3),
|
|
containerRefusal("expected_separator", 3),
|
|
],
|
|
["{key ", containerRefusal("expected_equals", 5)],
|
|
["{key = x,", containerRefusal("unexpected_character", 8)],
|
|
["{ /* unterminated", containerRefusal("unterminated_block_comment", 2)],
|
|
["(x, /* unterminated", containerRefusal("unterminated_block_comment", 4)],
|
|
["{ { toString = text; } @", containerRefusal("expected_equals", 23)],
|
|
] as const;
|
|
|
|
it.each(containerRefusals)(
|
|
"reports %s before and after a deep suffix",
|
|
(text, diagnosis, deep = diagnosis) => {
|
|
expect(syntaxFailure(() => decodeOpenStepPropertyList(text))).toMatchObject(
|
|
{ name: "OpenStepPropertyListError", ...diagnosis },
|
|
);
|
|
expect(
|
|
syntaxFailure(() => decodeOpenStepPropertyList(text + "(".repeat(130))),
|
|
).toMatchObject({ name: "OpenStepPropertyListError", ...deep });
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
'{ key = "unterminated',
|
|
'{ key = "escape\\',
|
|
"{ key = <01",
|
|
"{ { toString = text; } = value; }",
|
|
])(
|
|
"keeps the pinned scalar decoder's diagnosis for %s before a deep suffix",
|
|
(prefix) => {
|
|
for (const text of [prefix, prefix + "(".repeat(130)]) {
|
|
const pinned = syntaxFailure(() => parseOpenStep(text));
|
|
const owned = syntaxFailure(() => decodeOpenStepPropertyList(text));
|
|
expect(owned).not.toHaveProperty("name", "OpenStepPropertyListError");
|
|
expect(owned.constructor).toBe(pinned.constructor);
|
|
expect(owned.message).toBe(pinned.message);
|
|
}
|
|
},
|
|
);
|
|
|
|
it("retains every compound-coerced dictionary key with last assignment winning", () => {
|
|
const value = decodeOpenStepPropertyList(
|
|
'{ (__proto__) = first; (("__proto__")) = last; nested = { __proto__ = { x = y; }; }; constructor = text; }',
|
|
) as Record<string, unknown>;
|
|
expect(Object.getOwnPropertyDescriptor(value, "__proto__")?.value).toBe(
|
|
"last",
|
|
);
|
|
expect(Object.getPrototypeOf(value)).toBe(Object.prototype);
|
|
const nested = value["nested"] as object;
|
|
expect(Object.getOwnPropertyDescriptor(nested, "__proto__")?.value).toEqual({
|
|
x: "y",
|
|
});
|
|
expect(Object.getPrototypeOf(nested)).toBe(Object.prototype);
|
|
expect(JSON.stringify(value)).toBe(
|
|
'{"__proto__":"last","nested":{"__proto__":{"x":"y"}},"constructor":"text"}',
|
|
);
|
|
});
|
|
|
|
it("bounds compound keys and later siblings at their owning parse", () => {
|
|
const deep = "(".repeat(30_000) + "x" + ")".repeat(30_000);
|
|
for (const source of [`((x),${deep})`, `{(key)=${deep};}`, `{${deep}=x;}`])
|
|
expect(() => decodeOpenStepPropertyList(source)).toThrow(
|
|
/128 nesting levels/iu,
|
|
);
|
|
// A scalar key identifies its parent's member rather than adding value depth.
|
|
expect(decodeOpenStepPropertyList("{ key = (); }", 1)).toEqual({ key: [] });
|
|
expect(() => decodeOpenStepPropertyList("{ (key) = (); }", 1)).toThrow(
|
|
/1 nesting levels/iu,
|
|
);
|
|
});
|
|
|
|
it.each([
|
|
["(x,", "unexpected_end", 3],
|
|
["{ key =", "unexpected_end", 7],
|
|
] as const)("reports incomplete %s as %s at %s", (text, code, position) => {
|
|
expect(syntaxFailure(() => decodeOpenStepPropertyList(text))).toMatchObject({
|
|
name: "OpenStepPropertyListError",
|
|
code,
|
|
position,
|
|
});
|
|
});
|
|
|
|
it.each(["\n", "\r\n", "\r", "\u2028", "\u2029"])(
|
|
"ends OpenStep line comments at %j without dropping following values",
|
|
(newline) => {
|
|
const text =
|
|
"// leading" +
|
|
newline +
|
|
"{ kept = first; // inline" +
|
|
newline +
|
|
"hidden = second;\n items = (one, // array" +
|
|
newline +
|
|
"two,); }";
|
|
expect(startsOpenStepPropertyList(text)).toBe(true);
|
|
expect(decodeOpenStepPropertyList(text)).toEqual({
|
|
kept: "first",
|
|
hidden: "second",
|
|
items: ["one", "two"],
|
|
});
|
|
},
|
|
);
|
|
|
|
it("does not treat nonterminating whitespace or quoted comment text as line ends", () => {
|
|
expect(
|
|
decodeOpenStepPropertyList(
|
|
'{ kept = first; // comment\vhidden = second;\n text = "// still literal\rtext"; }',
|
|
),
|
|
).toEqual({ kept: "first", text: "// still literal\rtext" });
|
|
expect(startsOpenStepPropertyList("// comment without a line end")).toBe(
|
|
false,
|
|
);
|
|
const error = syntaxFailure(() =>
|
|
decodeOpenStepPropertyList("// comment without a line end"),
|
|
);
|
|
expect(error).toMatchObject({
|
|
name: "OpenStepPropertyListError",
|
|
code: "unexpected_end",
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
['{ CFBundleExecutable = "M\\U0061in"; }', { CFBundleExecutable: "Main" }],
|
|
['{ CFBundleExecutable = "M\\141in"; }', { CFBundleExecutable: "Main" }],
|
|
['{ "CFBundle\\U0045xecutable" = "Main"; }', { CFBundleExecutable: "Main" }],
|
|
['{ accent = "\\U00e9"; }', { accent: "é" }],
|
|
['{ nextstep = "\\335"; }', { nextstep: "é" }],
|
|
[
|
|
String.raw`{ escapes = "\n\r\t\0\"\\\q\137\U0041"; }`,
|
|
{ escapes: '\n\r\t\0"\\q_A' },
|
|
],
|
|
['{ controls = "\\a\\b\\f\\v"; }', { controls: "\u0007\b\f\v" }],
|
|
['{ surrogatePair = "\\Ud83d\\Ude00"; }', { surrogatePair: "😀" }],
|
|
['{ loneHighSurrogate = "\\Ud800"; }', { loneHighSurrogate: "\ufffd" }],
|
|
['{ loneLowSurrogate = "\\Udc00"; }', { loneLowSurrogate: "\ufffd" }],
|
|
['{ octalBoundary376 = "\\376"; }', { octalBoundary376: "\ufffd" }],
|
|
['{ octalBoundary377 = "\\377"; }', { octalBoundary377: "\ufffd" }],
|
|
['{ octalWrap400 = "\\400"; }', { octalWrap400: "\0" }],
|
|
])(
|
|
"decodes OpenStep quoted escape sequences in keys and values for %s",
|
|
(text, expected) => {
|
|
expect(decodeOpenStepPropertyList(text)).toEqual(expected);
|
|
},
|
|
);
|