diff --git a/docs/user-visible-errors.csv b/docs/user-visible-errors.csv
index 42d89b0654..1939afdb8c 100644
--- a/docs/user-visible-errors.csv
+++ b/docs/user-visible-errors.csv
@@ -36,6 +36,8 @@ BinaryTargetError,constraint=file_format_rejected; read permission denied,access
BinaryTargetError,constraint=load_selection_rejected,invalid_request,invalid_input,false
BinaryTargetError,constraint=bundle_type_unsupported,target_unavailable,unsupported_target,false
BinaryTargetError,constraint=bundle_type_unsupported; read permission denied,access_denied,unsupported_target,false
+BinaryTargetError,constraint=bundle_info_plist_decode_budget_exceeded,target_unavailable,unavailable,false
+BinaryTargetError,constraint=bundle_info_plist_decode_budget_exceeded; read permission denied,access_denied,unavailable,false
BinaryTargetError,constraint=bundle_info_plist_missing,target_unavailable,unavailable,false
BinaryTargetError,constraint=bundle_info_plist_missing; read permission denied,access_denied,unavailable,false
BinaryTargetError,constraint=bundle_layout_ambiguous,target_unavailable,unavailable,false
diff --git a/src/application/AppBundleExecutable.openStep.test.ts b/src/application/AppBundleExecutable.openStep.test.ts
index c3b7cfb589..9817767e25 100644
--- a/src/application/AppBundleExecutable.openStep.test.ts
+++ b/src/application/AppBundleExecutable.openStep.test.ts
@@ -4,6 +4,7 @@ import { join } from "node:path";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
+import { decodeOpenStepPropertyList } from "../domain/propertyListOpenStep.js";
import { resolveAppleBundleExecutable } from "./AppBundleExecutable.js";
it("resolves the declared executable from a commented OpenStep Info.plist", async () => {
@@ -23,3 +24,24 @@ it("resolves the declared executable from a commented OpenStep Info.plist", asyn
value: { executable, infoPlist },
});
});
+
+it("resolves an OpenStep Info.plist with quoted XML-looking text", async () => {
+ const root = await createTestTempDirectory("rea-openstep-doctype-");
+ const bundle = join(root, "Fixture.app");
+ const programs = join(bundle, "Contents", "MacOS");
+ const executable = join(programs, "Fixture");
+ const infoPlist = join(bundle, "Contents", "Info.plist");
+ const source = `{ CFBundleExecutable = Fixture; Note = " ]>"; }`;
+ expect(decodeOpenStepPropertyList(source)).toEqual({
+ CFBundleExecutable: "Fixture",
+ Note: " ]>",
+ });
+ await mkdir(programs, { recursive: true });
+ await writeFile(infoPlist, source);
+ await writeFile(executable, "fixture - never executed");
+
+ expect(await resolveAppleBundleExecutable(bundle)).toEqual({
+ ok: true,
+ value: { executable, infoPlist },
+ });
+});
diff --git a/src/application/AppBundleExecutable.test.ts b/src/application/AppBundleExecutable.test.ts
index b0be5a00d4..d761323c69 100644
--- a/src/application/AppBundleExecutable.test.ts
+++ b/src/application/AppBundleExecutable.test.ts
@@ -99,6 +99,30 @@ describe("app bundle Info.plist magic", () => {
});
});
+describe("app bundle Info.plist decode budget", () => {
+ it("refuses an XML Info.plist whose decoded representation exceeds the budget", async () => {
+ const root = await createTestTempDirectory("rea-app-plist-budget-");
+ const bundle = join(root, "Fixture.app");
+ const plistPath = join(bundle, "Contents", "Info.plist");
+ const executable = join(bundle, "Contents", "MacOS", "Fixture");
+ await mkdir(join(bundle, "Contents", "MacOS"), { recursive: true });
+ await writeFile(
+ plistPath,
+ `CFBundleExecutableFixturePadding${"a".repeat(5_000_000)}`,
+ );
+ await writeFile(executable, "inert fixture; never executed");
+
+ const result = await resolveAppleBundleExecutable(bundle);
+ expect(result).toMatchObject({
+ ok: false,
+ error: {
+ constraint: "bundle_info_plist_decode_budget_exceeded",
+ reason: expect.stringContaining("16 MiB"),
+ },
+ });
+ });
+});
+
describe("app bundle program directory containment", () => {
it("rejects an escaping programs directory before resolving its child", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-app-programs-"));
diff --git a/src/application/AppBundleExecutable.ts b/src/application/AppBundleExecutable.ts
index 5115644d26..c689cb7ddf 100644
--- a/src/application/AppBundleExecutable.ts
+++ b/src/application/AppBundleExecutable.ts
@@ -3,24 +3,21 @@ import { extname, join, sep } from "node:path";
import { z } from "zod";
-import { preflightPropertyListDecode } from "../domain/apple/propertyListDecodeBudget.js";
-import { decodeBinaryPropertyList } from "../domain/apple/binaryPlistMaterializer.js";
+import { isPlistDecodeBudgetFailure } from "../domain/apple/propertyListDecodeBudget.js";
+import { decodeInfoPlistValue } from "../domain/apple/infoPlist.js";
import { BinaryTargetError } from "../domain/configurationErrors.js";
import { isPathWithinRoot } from "../domain/localPath.js";
-import { parseXmlPropertyList } from "../domain/propertyListKeys.js";
-import { decodeXmlPlistText } from "../domain/propertyListXmlText.js";
-import { hasBinaryPlistSignature } from "../domain/apple/appleArchiveFormat.js";
import type {
BundleResourceRoot,
ResolvedAppBundleResourceRoot,
} from "../domain/apple/bundleResourceRoot.js";
-import { openableAppleBundleExtension } from "../domain/apple/appleBundleTypes.js";
+import {
+ INFO_PLIST_DECODE_MIB,
+ openableAppleBundleExtension,
+} from "../domain/apple/appleBundleTypes.js";
import { err, ok, type Result } from "../domain/result.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
-/** Decoded representation bound for one binary Info.plist. */
-const BINARY_PLIST_DECODE_BYTES = 16 * 1024 * 1024;
-
/** Where one app bundle layout keeps its Info.plist and program file. */
interface BundleLayout {
readonly name: BundleResourceRoot["layout"];
@@ -444,6 +441,18 @@ const resolveLayoutExecutable = async (
try {
name = executableName(decodeInfoPlistValue(plist, ["CFBundleExecutable"]));
} catch (cause: unknown) {
+ if (isPlistDecodeBudgetFailure(cause))
+ return err(
+ new BinaryTargetError(
+ plistPath,
+ `${noun} Info.plist decoded representation exceeds the ${INFO_PLIST_DECODE_MIB} MiB property list decode budget: ${plistPath} (${cause.message}). Shrink the Info.plist and retry.`,
+ {
+ cause,
+ constraint: "bundle_info_plist_decode_budget_exceeded",
+ infoPlist: plistPath,
+ },
+ ),
+ );
return err(
new BinaryTargetError(
plistPath,
@@ -520,36 +529,6 @@ const resolveLayoutExecutable = async (
}
};
-/**
- * Decode one Info.plist's top-level value in-process, binary or XML, so no
- * host plist tool is required. Values are read with format-aware parsers, not
- * patterns; an unrelated `__proto__` entry must not make the bundle unreadable.
- *
- * `keys` are the entries the caller reads. A plist that may declare one of
- * them more than once is refused: the decoder keeps the last declaration and
- * the system's bundle readers are not shown to agree. A repeat is attributed
- * to a key by name only, so a repeat inside a nested dictionary, or one whose
- * name was not retained, also refuses.
- */
-export const decodeInfoPlistValue = (
- plist: Buffer,
- keys: readonly string[],
-): unknown => {
- const decoded = hasBinaryPlistSignature(plist)
- ? decodeBinaryPropertyList(
- plist,
- preflightPropertyListDecode(plist, BINARY_PLIST_DECODE_BYTES),
- )
- : parseXmlPropertyList(decodeXmlPlistText(plist));
- const { names, namesOmitted } = decoded.duplicateKeys;
- const repeated = keys.filter((key) => namesOmitted || names.includes(key));
- if (repeated.length > 0)
- throw new TypeError(
- `Info.plist may declare ${repeated.join(", ")} more than once; which declaration applies is ambiguous`,
- );
- return decoded.value;
-};
-
/** The Info.plist decoded but declares no string CFBundleExecutable. */
class UndeclaredBundleExecutable extends Error {}
diff --git a/src/application/MacHopper.ts b/src/application/MacHopper.ts
index 7b8ca5683a..dfd6abd585 100644
--- a/src/application/MacHopper.ts
+++ b/src/application/MacHopper.ts
@@ -36,7 +36,7 @@ import {
macHopperReleaseMinimumSystemVersion,
} from "./HopperReleaseFeed.js";
import type { HopperInstallFailureReason } from "./SetupInstallFailure.js";
-import { decodeInfoPlistValue } from "./AppBundleExecutable.js";
+import { decodeInfoPlistValue } from "../domain/apple/infoPlist.js";
import {
macosMajorVersion,
macosVersionMeetsMinimum,
diff --git a/src/domain/analysisErrorClassification.test.ts b/src/domain/analysisErrorClassification.test.ts
index fa2aa6c365..a12a7770e8 100644
--- a/src/domain/analysisErrorClassification.test.ts
+++ b/src/domain/analysisErrorClassification.test.ts
@@ -82,3 +82,37 @@ it("keeps a refused target's constraint category beside its permission code", ()
),
).toMatchObject({ code: projected.code, category: projected.category });
});
+
+it("reports a budget-exceeded bundle target as its catalogue row", () => {
+ const projected = projectAnalysisError(
+ new BinaryTargetError("/target", "refused", {
+ constraint: "bundle_info_plist_decode_budget_exceeded",
+ }),
+ );
+ expect(projected).toMatchObject({
+ code: "target_unavailable",
+ category: "unavailable",
+ });
+ expect(
+ entry(
+ "BinaryTargetError",
+ "constraint=bundle_info_plist_decode_budget_exceeded",
+ ),
+ ).toMatchObject({ code: projected.code, category: projected.category });
+ const denied = projectAnalysisError(
+ new BinaryTargetError("/target", "refused", {
+ constraint: "bundle_info_plist_decode_budget_exceeded",
+ cause: Object.assign(new Error("denied"), { code: "EACCES" }),
+ }),
+ );
+ expect(denied).toMatchObject({
+ code: "access_denied",
+ category: "unavailable",
+ });
+ expect(
+ entry(
+ "BinaryTargetError",
+ "constraint=bundle_info_plist_decode_budget_exceeded; read permission denied",
+ ),
+ ).toMatchObject({ code: denied.code, category: denied.category });
+});
diff --git a/src/domain/analysisErrorClassification.ts b/src/domain/analysisErrorClassification.ts
index dafd2058a9..02b0b741da 100644
--- a/src/domain/analysisErrorClassification.ts
+++ b/src/domain/analysisErrorClassification.ts
@@ -180,6 +180,10 @@ const BINARY_TARGET_CLASSIFICATIONS = {
"target_unavailable",
"unsupported_target",
),
+ bundle_info_plist_decode_budget_exceeded: classified(
+ "target_unavailable",
+ "unavailable",
+ ),
bundle_info_plist_missing: classified("target_unavailable", "unavailable"),
bundle_layout_ambiguous: classified("target_unavailable", "unavailable"),
bundle_executable_undeclared: classified("target_unavailable", "unavailable"),
diff --git a/src/domain/analysisErrorPresentation.ts b/src/domain/analysisErrorPresentation.ts
index 0d5055a316..7568562aeb 100644
--- a/src/domain/analysisErrorPresentation.ts
+++ b/src/domain/analysisErrorPresentation.ts
@@ -11,7 +11,10 @@ import {
AnalysisTimeoutError,
} from "./analysisErrorCore.js";
import { ArtifactOperationError } from "./artifactOperationError.js";
-import { OPENABLE_APPLE_BUNDLE_TYPES_TEXT } from "./apple/appleBundleTypes.js";
+import {
+ INFO_PLIST_DECODE_MIB,
+ OPENABLE_APPLE_BUNDLE_TYPES_TEXT,
+} from "./apple/appleBundleTypes.js";
import {
BinaryTargetError,
ConfigurationError,
@@ -186,6 +189,11 @@ export const analysisErrorRemediationAction = (
error.infoPlist !== undefined
)
return `Read ${error.infoPlist} with inspect_plist to review its CFBundleExecutable, then select an existing program file directly.`;
+ if (
+ error instanceof BinaryTargetError &&
+ error.constraint === "bundle_info_plist_decode_budget_exceeded"
+ )
+ return `Reduce the Info.plist below the ${INFO_PLIST_DECODE_MIB} MiB decoded representation allowance, then retry opening the bundle.`;
if (
error instanceof BinaryTargetError &&
(error.constraint === "bundle_info_plist_missing" ||
diff --git a/src/domain/apple/appleBundleTypes.ts b/src/domain/apple/appleBundleTypes.ts
index 3738579283..341c670192 100644
--- a/src/domain/apple/appleBundleTypes.ts
+++ b/src/domain/apple/appleBundleTypes.ts
@@ -44,3 +44,6 @@ export const isUnopenedAppleBundleExtension = (extension: string): boolean =>
/** Caller-facing list of the bundle directories binary routes open. */
export const OPENABLE_APPLE_BUNDLE_TYPES_TEXT =
OPENABLE_APPLE_BUNDLE_EXTENSIONS.join(", ");
+
+/** Decoded representation allowance for a binary or XML Info.plist, in MiB. */
+export const INFO_PLIST_DECODE_MIB = 16;
diff --git a/src/domain/apple/infoPlist.ts b/src/domain/apple/infoPlist.ts
new file mode 100644
index 0000000000..f847607b9e
--- /dev/null
+++ b/src/domain/apple/infoPlist.ts
@@ -0,0 +1,44 @@
+import { malformedInput } from "../parseFailure.js";
+import { parseXmlPropertyList } from "../propertyListKeys.js";
+import { decodeXmlPlistText } from "../propertyListXmlText.js";
+import { hasBinaryPlistSignature } from "./appleArchiveFormat.js";
+import { INFO_PLIST_DECODE_MIB } from "./appleBundleTypes.js";
+import { decodeBinaryPropertyList } from "./binaryPlistMaterializer.js";
+import { MAX_PLIST_DEPTH } from "./plistValue.js";
+import { estimateBinaryPlistExpansion } from "./propertyListDecodeBudget.js";
+
+const INFO_PLIST_DECODE_BYTES = INFO_PLIST_DECODE_MIB * 1024 * 1024;
+
+/**
+ * Decode one Info.plist's top-level value in-process, whether binary, XML, or
+ * OpenStep. An unrelated `__proto__` entry must not make the bundle unreadable.
+ *
+ * `keys` are the entries the caller reads. A plist that may declare one of
+ * them more than once is refused: the decoder keeps the last declaration and
+ * the system's bundle readers are not shown to agree. A repeat is attributed
+ * to a key by name only, so a repeat inside a nested dictionary, or one whose
+ * name was not retained, also refuses.
+ */
+export const decodeInfoPlistValue = (
+ plist: Buffer,
+ keys: readonly string[],
+): unknown => {
+ const decoded = hasBinaryPlistSignature(plist)
+ ? decodeBinaryPropertyList(
+ plist,
+ estimateBinaryPlistExpansion(plist, INFO_PLIST_DECODE_BYTES),
+ )
+ : parseXmlPropertyList(
+ decodeXmlPlistText(plist),
+ MAX_PLIST_DEPTH,
+ INFO_PLIST_DECODE_BYTES,
+ );
+ const { names, namesOmitted } = decoded.duplicateKeys;
+ const repeated = keys.filter((key) => namesOmitted || names.includes(key));
+ if (repeated.length > 0)
+ throw malformedInput(
+ "plist",
+ `Info.plist may declare ${repeated.join(", ")} more than once; which declaration applies is ambiguous`,
+ );
+ return decoded.value;
+};
diff --git a/src/domain/apple/propertyListDecodeBudget.ts b/src/domain/apple/propertyListDecodeBudget.ts
index e423253166..3f2b08bd73 100644
--- a/src/domain/apple/propertyListDecodeBudget.ts
+++ b/src/domain/apple/propertyListDecodeBudget.ts
@@ -19,6 +19,8 @@ import {
binaryPlistUidNormalizationWidth,
} from "./plistScalars.js";
+const DEFAULT_PLIST_DECODE_BUDGET = "the property list decode budget";
+
/** Preflight the representation created by the pinned plist decoder. */
export const preflightPropertyListDecode = (
bytes: Buffer,
@@ -32,40 +34,54 @@ export const preflightPropertyListDecode = (
const {
numberProjection = false,
uidProjection = false,
- budget = "the property list decode budget",
+ budget = DEFAULT_PLIST_DECODE_BUDGET,
} = options;
- const expansion = hasBinaryPlistSignature(bytes)
- ? estimateBinaryPlistExpansion(bytes, maxBytes, {
- numberProjection,
- uidProjection,
- budget,
- })
- : {
- estimatedBytes: estimateXmlPlistExpansion(
- bytes,
- maxBytes,
- xmlText,
- numberProjection,
- budget,
- ),
+ if (hasBinaryPlistSignature(bytes))
+ return estimateBinaryPlistExpansion(bytes, maxBytes, {
+ numberProjection,
+ uidProjection,
+ budget,
+ });
+ return {
+ estimatedBytes: preflightXmlPropertyListDecode(
+ xmlText ?? decodeXmlPlistText(bytes),
+ maxBytes,
+ { numberProjection, budget },
+ ),
+ datePrecisionOverlapCount: 0,
+ reachableDateOffsets: [],
+ overlappingDateOffsets: [],
+ reachableWideIntegerOffsets: [],
+ overlappingWideIntegerOffsets: [],
+ reachableNumericOffsets: [],
+ uidOffsetsToNormalize: [],
+ containersToNormalize: [],
+ normalizedOffsetSize: 1,
+ normalizedReferenceSize: 1,
+ };
+};
- datePrecisionOverlapCount: 0,
- reachableDateOffsets: [],
- overlappingDateOffsets: [],
- reachableWideIntegerOffsets: [],
- overlappingWideIntegerOffsets: [],
- reachableNumericOffsets: [],
- uidOffsetsToNormalize: [],
- containersToNormalize: [],
- normalizedOffsetSize: 1,
- normalizedReferenceSize: 1,
- };
- if (expansion.estimatedBytes > maxBytes)
+/** Refuse an XML plist whose decoded representation exceeds the byte allowance. */
+export const preflightXmlPropertyListDecode = (
+ xml: string,
+ maxBytes: number,
+ {
+ numberProjection = false,
+ budget = DEFAULT_PLIST_DECODE_BUDGET,
+ }: Pick = {},
+): number => {
+ const estimatedBytes = estimateXmlPlistExpansion(
+ xml,
+ maxBytes,
+ numberProjection,
+ budget,
+ );
+ if (estimatedBytes > maxBytes)
throw decodeBudgetExceeded(
`plist representation exceeds ${budget}`,
maxBytes,
);
- return expansion;
+ return estimatedBytes;
};
/**
@@ -80,13 +96,11 @@ const XML_NODE_BYTES = 384;
const XML_REFERENCE_BYTES = 64;
const estimateXmlPlistExpansion = (
- bytes: Buffer,
+ xml: string,
maxBytes: number,
- xmlText: string | undefined,
numberProjection: boolean,
budget: string,
): number => {
- const xml = xmlText ?? decodeXmlPlistText(bytes);
// The decoded text and the DOM's copies of its character data.
let estimate = xml.length * 4;
const elementBytes =
@@ -347,7 +361,7 @@ export const estimateBinaryPlistExpansion = (
bytes: Buffer,
maxBytes: number,
{
- budget = "the property list decode budget",
+ budget = DEFAULT_PLIST_DECODE_BUDGET,
bounds = "strict",
numberProjection = false,
uidProjection = false,
diff --git a/src/domain/configurationErrors.ts b/src/domain/configurationErrors.ts
index d6febdbf71..e31720678f 100644
--- a/src/domain/configurationErrors.ts
+++ b/src/domain/configurationErrors.ts
@@ -54,6 +54,7 @@ export class NoBinaryOpenError extends AnalysisError {
/** Apple bundle resolution outcomes that leave no program file to open. */
export type BundleTargetConstraint =
| "bundle_type_unsupported"
+ | "bundle_info_plist_decode_budget_exceeded"
| "bundle_info_plist_missing"
| "bundle_layout_ambiguous"
| "bundle_executable_undeclared"
diff --git a/src/domain/propertyListKeys.ts b/src/domain/propertyListKeys.ts
index e7718659dc..213e61afd3 100644
--- a/src/domain/propertyListKeys.ts
+++ b/src/domain/propertyListKeys.ts
@@ -1,4 +1,5 @@
import { decodeXmlPropertyList } from "./propertyListXml.js";
+import { preflightXmlPropertyListDecode } from "./apple/propertyListDecodeBudget.js";
import {
decodeOpenStepPropertyList,
startsOpenStepPropertyList,
@@ -21,13 +22,20 @@ export interface ParsedPropertyList {
readonly duplicateKeys: PlistDuplicateKeys;
}
-/** Decode XML or the existing OpenStep container form, retaining every dictionary key. */
+/** Decode XML or the existing OpenStep container form, retaining every dictionary key.
+ * The optional XML byte budget applies after format selection. In OpenStep,
+ * quoted markup is string data and does not introduce XML expansion.
+ */
export const parseXmlPropertyList = (
text: string,
maximumDepth = MAX_PLIST_DEPTH,
+ maximumXmlDecodeBytes?: number,
): ParsedPropertyList => {
- if (!startsOpenStepPropertyList(text))
+ if (!startsOpenStepPropertyList(text)) {
+ if (maximumXmlDecodeBytes !== undefined)
+ preflightXmlPropertyListDecode(text, maximumXmlDecodeBytes);
return decodeXmlPropertyList(text, maximumDepth);
+ }
const duplicates = createPlistDuplicateKeyCollector();
return {
value: decodeOpenStepPropertyList(text, maximumDepth, duplicates),