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");