mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 22:15:50 +00:00
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`.
This commit is contained in:
1 parent
c0963732a7
commit
f03cce9c01
3 files changed
+38
-4
No files matched your search
@@ -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 `<deadbeef>`, report
|
||||
`unknown` even when plutil decodes their values through an XML conversion.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -167,6 +167,37 @@ it.for<TextSourceCase>([
|
||||
],
|
||||
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(
|
||||
'<?xml version="1.0"?><plist><dict><key>name</key><string>\u0003</string></dict></plist>',
|
||||
),
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user