fix(apple): decode bundle plist bytes before executable lookup

This commit is contained in:
morluto
2026-10-09 06:32:09 +08:00
parent 6495171812
commit d575a7340b
7 changed files with 200 additions and 10 deletions
@@ -26,7 +26,7 @@ import {
} from "./NibViewHierarchy.js";
import { jsonValueSchema, type JsonValue } from "../../domain/jsonValue.js";
import { decodeXmlPlistText } from "./XmlPropertyListText.js";
import { decodeXmlPlistText } from "../../domain/propertyListXmlText.js";
const MAX_AGGREGATE_INPUT_BYTES = 32 * 1024 * 1024;
const MAX_AGGREGATE_DECODE_BYTES = 256 * 1024 * 1024;
@@ -1,4 +1,4 @@
import { decodeXmlPlistText } from "./XmlPropertyListText.js";
import { decodeXmlPlistText } from "../../domain/propertyListXmlText.js";
/** Reason reported when an archive would exceed the shared decoding budget. */
export type InterfaceBuilderBudgetReason = "aggregate_decode_budget_exhausted";
+1 -1
View File
@@ -16,7 +16,7 @@ import {
import { DirectoryArtifactReader } from "../DirectoryArtifactReader.js";
import { ArtifactReaderFailure } from "../ArtifactReader.js";
import { decodeXmlPlistText } from "./XmlPropertyListText.js";
import { decodeXmlPlistText } from "../../domain/propertyListXmlText.js";
const MAX_BYTES = 64 * 1024 * 1024;
@@ -1,30 +0,0 @@
import { TextDecoder } from "node:util";
/** Decode BOM-aware XML plist text with fatal byte validation. */
export const decodeXmlPlistText = (bytes: Buffer): string => {
const encoding =
bytes[0] === 0xff && bytes[1] === 0xfe
? "utf-16le"
: bytes[0] === 0xfe && bytes[1] === 0xff
? "utf-16be"
: "utf-8";
const text = new TextDecoder(encoding, { fatal: true }).decode(bytes);
const declaration = /^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/u.exec(
text,
)?.[1];
const declared = declaration?.toLowerCase();
if (
declared !== undefined &&
!["utf-8", "utf-16", "utf-16le", "utf-16be"].includes(declared)
)
throw new TypeError(
`Unsupported XML encoding declaration: ${declaration}. Supported encodings are UTF-8 and BOM-marked UTF-16 in either byte order.`,
);
if (
declared !== undefined &&
declared !== encoding &&
!(encoding !== "utf-8" && declared === "utf-16")
)
throw new TypeError("XML encoding declaration disagrees with its bytes");
return text;
};