fix(native): let plutil decide XML plists REA's reader refuses (#12251)

CoreFoundation reads some XML plists that strict XML rejects, such as
documents with a double hyphen in a comment or a control character in a
string. inspect_plist refused them although plutil -lint accepts them,
and the outcome depended on how file(1) described the bytes.

When REA's XML reader refuses a document's syntax, inspection now takes
the existing plutil conversion route. The result keeps format xml and a
limitation names REA's reason. A document plutil also rejects stays
refused with its diagnostic, and plist structure errors in well-formed
XML are still refused without conversion.

Fixes #12234
This commit is contained in:
Oke Iyanuoluwa Enoch authored and GitHub committed 2026-11-19 06:15:08 -05:00
1 parent 247f919a63
commit 41db934de8
4 files changed
+151 -6

No files matched your search

+5 -1
View File
@@ -723,7 +723,11 @@ directly when their number facts need no further classification; explicitly
identified JSON sources can have scalar roots. Unidentified primitive text keeps
its existing conversion route, so OpenStep `123` remains a string. OpenStep,
unsupported XML encodings such as UTF-32 and declared legacy encodings, and JSON
numbers requiring XML type facts retain the `plutil` route. Invalid UTF-8 and
numbers requiring XML type facts retain the `plutil` route. So does XML that
REA's XML reader rejects as not well-formed, which CoreFoundation can still
accept: a limitation names REA's reason, and a document `plutil` also rejects
stays refused with its diagnostic. Plist structure errors in well-formed XML
remain refusals without conversion. Invalid UTF-8 and
encoding-declaration mismatches remain explicit failures. Direct-source
provenance records `file` without claiming conversion; conversion limitations
and invocations appear only when conversion actually ran.
+34 -1
View File
@@ -145,6 +145,7 @@ import {
type ParsedPlist,
} from "./parsers/plist.js";
import { XmlPlistTextDecodeError } from "../domain/propertyListXmlText.js";
import { ParseFailureError } from "../domain/parseFailure.js";
import {
architectureLocations,
inspectNativeMacho,
@@ -1289,6 +1290,14 @@ class NativeMacOSClient implements AnalysisClient {
parsed.error.reason === "unsupported-encoding"
)
return undefined;
const refusal = parsed.ok ? undefined : xmlSyntaxRefusal(parsed.error);
if (refusal !== undefined)
return await this.#inspectConvertedPlist(
fileInput,
classified,
format,
refusal,
);
} else {
const json = readPlistJsonSource(source.value);
if (
@@ -1325,6 +1334,7 @@ class NativeMacOSClient implements AnalysisClient {
fileInput: NativePlistReadContext,
classified: NativeCommandCapture,
format: z.infer<typeof inspectPlistSchema>["format"],
sourceRefusal?: string,
): Promise<Result<NativeObservation, AnalysisError>> {
const { path } = fileInput.selection;
const { signal, timeoutMs } = fileInput;
@@ -1374,7 +1384,16 @@ class NativeMacOSClient implements AnalysisClient {
].map((item) => invocation(item, path, "$PLIST"));
return ok(
nativePlistObservation({
parsed: parsed.value,
parsed:
sourceRefusal === undefined
? parsed.value
: {
...parsed.value,
limitations: [
`REA's XML reader refused the source (${sourceRefusal}), but plutil read it, so the value comes from plutil's conversion rather than the original text.`,
...parsed.value.limitations,
],
},
format,
path,
resourceRoot: this.bundleResourceRoot,
@@ -2244,6 +2263,20 @@ const nativePlistDecodeFailure = (
);
};
/**
* The reason REA's XML reader refused a plist's syntax. CoreFoundation accepts
* some documents that strict XML rejects (#12234), so plutil decides those.
* Plist structure errors and refused document types are not syntax refusals.
*/
const xmlSyntaxRefusal = (error: unknown): string | undefined => {
const cause = error instanceof AnalysisOutputError ? error.cause : undefined;
return cause instanceof ParseFailureError &&
cause.failure.format === "xml" &&
cause.kind === "malformed"
? cause.message
: undefined;
};
const plutilDiagnostic = (
capture: Pick<NativeCommandCapture, "stdout" | "stderr">,
path: string,
@@ -141,6 +141,32 @@ it.for<TextSourceCase>([
value: { name: "UTF32 control" },
conversions: [{ format: "json", output: '{"name":"UTF32 control"}' }],
},
{
name: "malformed XML comment that plutil reads",
bytes: Buffer.from(
'<?xml version="1.0"?><!-- a -- b --><plist><dict><key>name</key><string>x</string></dict></plist>',
),
description: "XML 1.0 document text",
format: "xml",
value: { name: "x" },
limitations: [
"REA's XML reader refused the source (XML is not well-formed: 1:31: malformed comment.), but plutil read it, so the value comes from plutil's conversion rather than the original text.",
],
conversions: [{ format: "json", output: '{"name":"x"}' }],
},
{
name: "XML control character that plutil reads",
bytes: Buffer.from(
"<plist><dict><key>name</key><string></string></dict></plist>",
),
description: "XML 1.0 document text",
format: "xml",
value: { name: "" },
limitations: [
"REA's XML reader refused the source (XML is not well-formed: 1:37: disallowed character.), but plutil read it, so the value comes from plutil's conversion rather than the original text.",
],
conversions: [{ format: "json", output: '{"name":"\\u0001"}' }],
},
])("owns $name interpretation before optional conversion", async (fixture) => {
const root = await createTestTempDirectory("rea-plist-text-source-");
const path = join(root, "selected.plist");
@@ -214,3 +240,68 @@ it.for<TextSourceCase>([
);
expect(Buffer.compare(await readFile(path), fixture.bytes)).toBe(0);
});
const inspectRefusal = async (
bytes: string,
conversions: readonly string[],
): Promise<{ readonly error: unknown; readonly tools: readonly string[] }> => {
const root = await createTestTempDirectory("rea-plist-text-refusal-");
const path = join(root, "selected.plist");
await writeFile(path, bytes);
const replay = new NativeFixtureRunner({ file: "XML 1.0 document text" });
const tools: string[] = [];
const client = new NativeMacOSProvider(
{},
{
async run(tool, args) {
tools.push(tool === "plutil" ? `plutil ${args[0]} ${args[1]}` : tool);
const result = await replay.run(tool, args);
if (
tool !== "plutil" ||
!result.ok ||
!conversions.includes(args[1] ?? "")
)
return result;
return ok({
...result.value,
stdout: "",
stdoutBytes: 0,
stderr: `${path}: Property List error`,
exitCode: 1,
});
},
},
"darwin",
).createClient(nativeMachoTarget(join(root, "target")));
onTestFinished(async () => {
await client.close();
});
const inspected = await client.execute("inspect_plist", { path });
return { error: inspected.ok ? undefined : inspected.error, tools };
};
it("refuses malformed XML that plutil also rejects (#12234)", async () => {
const { error, tools } = await inspectRefusal(
'<?xml version="1.0"?><!-- a -- b --><plist><dict/></plist>',
["json", "xml1"],
);
expect(error).toMatchObject({
issues: [{ message: expect.stringMatching(/plutil could not decode/u) }],
});
expect(tools).toEqual([
"file",
"plutil -convert json",
"plutil -convert xml1",
]);
});
it("keeps refusing a well-formed XML plist with an invalid structure", async () => {
const { error, tools } = await inspectRefusal(
"<plist><array><unknown/></array></plist>",
[],
);
expect(error).toMatchObject({
issues: [{ message: expect.stringMatching(/Invalid PLIST tag unknown/u) }],
});
expect(tools).toEqual(["file"]);
});
@@ -1538,7 +1538,7 @@ describe("native plist defaults for iOS-style bundles", () => {
});
});
it("rejects malformed selected plist bytes before mocked conversion can invent facts", async () => {
it("rejects malformed selected plist bytes that plutil also rejects instead of inventing facts", async () => {
directory = await createTestTempDirectory("rea-native-malformed-plist-");
const app = join(directory, "Malformed.app");
const path = join(app, "Contents/Info.plist");
@@ -1547,9 +1547,19 @@ it("rejects malformed selected plist bytes before mocked conversion can invent f
const tools: string[] = [];
const replay = new FixtureRunner();
const runner: NativeCommandRunner = {
run(tool, arguments_, options) {
async run(tool, arguments_, options) {
tools.push(tool);
return replay.run(tool, arguments_, options);
const result = await replay.run(tool, arguments_, options);
// REA's XML reader refuses these bytes, so plutil decides (#12234);
// like the real tool, it rejects them rather than printing a plist.
if (tool !== "plutil" || !result.ok) return result;
return ok({
...result.value,
stdout: "",
stdoutBytes: 0,
stderr: `${path}: Property List error`,
exitCode: 1,
});
},
};
const client = new NativeMacOSProvider({}, runner, "darwin").createClient(
@@ -1565,7 +1575,14 @@ it("rejects malformed selected plist bytes before mocked conversion can invent f
error: { _tag: tag, operation: "inspect_plist" },
});
}
expect(tools).toEqual(["file", "file"]);
expect(tools).toEqual([
"file",
"plutil",
"plutil",
"file",
"plutil",
"plutil",
]);
expect(await readFile(path, "utf8")).toBe("fixture");
});