Merge pull request #885 from morluto/fix/plist-prototype-keys

fix(plist): read XML plists containing a __proto__ key
This commit is contained in:
Kaoru0822
2026-10-07 00:46:50 -07:00
committed by GitHub
10 changed files with 278 additions and 28 deletions
+2 -2
View File
@@ -8,7 +8,6 @@ import { observeNativeUi } from "./NativeUiObservation.js";
import { dirname, isAbsolute, resolve } from "node:path";
import { open, realpath, stat } from "node:fs/promises";
import { parse as parseXmlPlist } from "plist";
import { z } from "zod";
import {
@@ -35,6 +34,7 @@ import { BinaryTargetError } from "../domain/configurationErrors.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
import { parseXmlPropertyList } from "../domain/propertyListKeys.js";
import {
demangleSwiftSchema,
inspectPlistSchema,
@@ -645,7 +645,7 @@ const parseEntitlements = (output: string): JsonValue | null => {
const end = output.lastIndexOf("</plist>");
if (start < 0 || end < start) return null;
return jsonValueSchema.parse(
parseXmlPlist(output.slice(start, end + "</plist>".length)),
parseXmlPropertyList(output.slice(start, end + "</plist>".length)).value,
);
};
+20 -5
View File
@@ -1,4 +1,3 @@
import { parse as parseXmlPlist } from "plist";
import { z } from "zod";
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
@@ -7,6 +6,11 @@ import {
projectPlistValue,
type ProjectedPlistValue,
} from "../../domain/plistValue.js";
import {
omitPrototypeKeys,
omittedPrototypeKeysLimitation,
parseXmlPropertyList,
} from "../../domain/propertyListKeys.js";
import { err, ok, type Result } from "../../domain/result.js";
const plistObject = z.record(z.string(), z.unknown());
@@ -99,9 +103,9 @@ export const parsePlistJson = (
ambiguousNumberCount += 1;
return item;
};
let value: unknown;
let decoded: ReturnType<typeof omitPrototypeKeys>;
try {
value = decodePlistJson(output, classify);
decoded = omitPrototypeKeys(decodePlistJson(output, classify));
} catch (cause: unknown) {
return err(
new AnalysisOutputError(
@@ -111,10 +115,14 @@ export const parsePlistJson = (
),
);
}
const { value } = decoded;
return ok({
value,
bundle: projectPlistBundle(value),
limitations: numberLimitations(exactIntegerCount, ambiguousNumberCount),
limitations: [
...numberLimitations(exactIntegerCount, ambiguousNumberCount),
...prototypeKeyLimitations(decoded.omittedPrototypeKeys),
],
});
};
@@ -126,8 +134,11 @@ export const parsePlistXml = (
output: string,
): Result<ParsedPlist, AnalysisOutputError> => {
let projected: ProjectedPlistValue;
let omittedPrototypeKeys: number;
try {
projected = projectPlistValue(parseXmlPlist(output));
const decoded = parseXmlPropertyList(output);
omittedPrototypeKeys = decoded.omittedPrototypeKeys;
projected = projectPlistValue(decoded.value);
} catch (cause: unknown) {
return err(
new AnalysisOutputError(
@@ -168,6 +179,7 @@ export const parsePlistXml = (
`${String(projected.unknownRealCount)} non-finite real value(s) are reported as { "$plist_type": "real", "value": null } because the XML decoder does not distinguish NaN from infinity.`,
]),
...numberLimitations(exactIntegerCount, ambiguousNumberCount),
...prototypeKeyLimitations(omittedPrototypeKeys),
],
});
};
@@ -201,6 +213,9 @@ const xmlNumberLiterals = (xml: string): XmlNumberLiterals => {
return { integers, reals };
};
const prototypeKeyLimitations = (count: number): string[] =>
count === 0 ? [] : [omittedPrototypeKeysLimitation(count)];
const numberLimitations = (
exactIntegerCount: number,
ambiguousNumberCount: number,