From f03cce9c01d184ffade34dcb36fd05c0c0350a5e Mon Sep 17 00:00:00 2001 From: Brahma Reddy <165083892+13v13reddy@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:00:31 -0600 Subject: [PATCH] fix(native): label XML plists that file calls data as xml (#12910) `file -b` reports `data` for an XML plist containing a control character or NUL byte, which CoreFoundation still reads. plistSourceFormat only probed the source for markup when `file` reported text, so these sources were labelled `unknown` and skipped REA's XML reader. When that reader would have refused them, the result also lacked the limitation that says the value came from plutil's conversion. Two plists shipped with macOS 27.2.1 are affected. Probe the source prefix for any description that does not name binary, XML or JSON. Such XML now takes the same route as XML that `file` recognizes: REA's reader decodes it directly, or #12251's plutil fallback records REA's refusal reason. OpenStep and other non-markup sources stay `unknown`. --- docs/guides/native/native-investigation.md | 6 ++-- src/native/NativePlistSource.ts | 5 +-- .../native/nativePlistTextSource.test.ts | 31 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/guides/native/native-investigation.md b/docs/guides/native/native-investigation.md index 3f7e8bfc57..50853ac504 100644 --- a/docs/guides/native/native-investigation.md +++ b/docs/guides/native/native-investigation.md @@ -716,8 +716,10 @@ marker in their reported slices. `inspect_plist.format` describes the selected source, not plutil's conversion format. Sources explicitly identified as XML, binary or JSON retain those -labels. For generic text, a bounded source-prefix probe recognizes leading XML -markup, including UTF-8 and BOM-marked UTF-16 sources. Unidentified text and +labels. For any other `file` description, a bounded source-prefix probe +recognizes leading XML markup, including UTF-8 and BOM-marked UTF-16 sources. +`file` reports `data` for XML containing a control character or NUL byte, which +CoreFoundation can still read; the probe labels it `xml`. Unidentified text and OpenStep plists, including a data-only value such as ``, report `unknown` even when plutil decodes their values through an XML conversion. diff --git a/src/native/NativePlistSource.ts b/src/native/NativePlistSource.ts index 30be2bcd1d..0fed3419ae 100644 --- a/src/native/NativePlistSource.ts +++ b/src/native/NativePlistSource.ts @@ -530,7 +530,7 @@ const readPlistSourceBytes = async ( }; /** - * Bytes examined for leading markup when `file` reports only text. + * Bytes examined for leading markup when `file` does not name the format. * This is a probe window, not a document cap, and has no runtime override. */ const PLIST_MARKUP_PROBE_BYTES = 4096; @@ -543,7 +543,8 @@ export const plistSourceFormat = ( if (/binary property list/iu.test(description)) return "binary"; if (/\bXML\b/iu.test(description)) return "xml"; if (/\bJSON\b/iu.test(description)) return "json"; - if (!/\btext\b/iu.test(description)) return "unknown"; + // `file` reports `data` for XML containing a control character or NUL byte, + // which CoreFoundation can still read, so the source decides the label. const head = source.subarray(0, PLIST_MARKUP_PROBE_BYTES); const encoding = head[0] === 0xff && head[1] === 0xfe diff --git a/tests/boundary/providers/native/nativePlistTextSource.test.ts b/tests/boundary/providers/native/nativePlistTextSource.test.ts index 3bdff08478..2ea0d42f8a 100644 --- a/tests/boundary/providers/native/nativePlistTextSource.test.ts +++ b/tests/boundary/providers/native/nativePlistTextSource.test.ts @@ -167,6 +167,37 @@ it.for([ ], conversions: [{ format: "json", output: '{"name":"\\u0001"}' }], }, + { + // `file -b` reports `data` for this XML, as it does for some shipped + // macOS plists such as NeptuneOneWallpaper.appex's Info.plist. + name: "XML control character that file calls data", + bytes: Buffer.from( + 'name\u0003', + ), + description: "data", + format: "xml", + value: { name: "\u0003" }, + limitations: [ + "REA's XML reader refused the source (XML is not well-formed: 1:58: disallowed character.), but plutil read it, so the value comes from plutil's conversion rather than the original text.", + ], + conversions: [{ format: "json", output: '{"name":"\\u0003"}' }], + }, + { + name: "well-formed XML that file calls data", + bytes: Buffer.from(xml), + description: "data", + format: "xml", + value: xmlValue, + conversions: [], + }, + { + name: "OpenStep control character that file calls data", + bytes: Buffer.from('{ name = "\u0003"; }'), + description: "data", + format: "unknown", + value: { name: "\u0003" }, + conversions: [{ format: "json", output: '{"name":"\\u0003"}' }], + }, ])("owns $name interpretation before optional conversion", async (fixture) => { const root = await createTestTempDirectory("rea-plist-text-source-"); const path = join(root, "selected.plist");