Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(artifacts): reject malformed serialized keys and integer values

morluto9435c7aae279
diff --git a/src/artifacts/apple/InterfaceBuilderDecodeBudget.ts b/src/artifacts/apple/InterfaceBuilderDecodeBudget.ts
index 8469d93f0..3593fa43e 100644
--- a/src/artifacts/apple/InterfaceBuilderDecodeBudget.ts
+++ b/src/artifacts/apple/InterfaceBuilderDecodeBudget.ts
@@ -170,8 +170,8 @@ export interface BinaryPlistExpansionOptions {
readonly fail?: (kind: BinaryPlistExpansionFailure, message: string) => Error;
/**
* Structural bounds: "strict" keeps objects and the offset table before the
- * trailer; "decoder" admits exactly what plist.parseBinary can read, so
- * expansion is bounded without rejecting archives that decoder accepts.
+ * trailer; "decoder" follows the decoder's object-table boundary policy
+ * while still rejecting structures whose coercion would lose plist facts.
*/
readonly bounds?: "strict" | "decoder";
}
@@ -267,6 +267,8 @@ export const estimateBinaryPlistExpansion = (
throw new TypeError("binary plist object offset is invalid");
const marker = bytes[offset] ?? 0;
const type = marker >> 4;
+ if (entry.dictionaryKey && type !== 5 && type !== 6)
+ throw new TypeError("binary plist dictionary key is not a string");
let size = marker & 0x0f;
let cursor = offset + 1;
if (size === 0x0f && type !== 0 && type !== 8) {
diff --git a/src/artifacts/apple/KeyedArchiveReader.test.ts b/src/artifacts/apple/KeyedArchiveReader.test.ts
index b619788a1..a0b0f1b73 100644
--- a/src/artifacts/apple/KeyedArchiveReader.test.ts
+++ b/src/artifacts/apple/KeyedArchiveReader.test.ts
@@ -219,6 +219,37 @@ const keyedRoot = (payload: readonly Buffer[]): Buffer =>
describe("binary plist reference preflight", () => {
const selection = { offset: 0, limit: 10 };
+ it("rejects an array key that coerces to __proto__ before parsing", () => {
+ expect(() =>
+ decodeKeyedArchiveBytes(
+ keyedRoot([
+ plistArray([9]),
+ Buffer.from([0xd1, 0, 10, 0, 11]),
+ plistArray([12]),
+ Buffer.from([0xd1, 0, 13, 0, 14]),
+ plistString("__proto__"),
+ plistString("lost"),
+ plistString("value"),
+ ]),
+ selection,
+ ),
+ ).toThrow("binary plist dictionary key is not a string");
+ });
+
+ it("rejects binary data dictionary keys", () => {
+ expect(() =>
+ decodeKeyedArchiveBytes(
+ keyedRoot([
+ plistArray([9]),
+ Buffer.from([0xd1, 0, 10, 0, 11]),
+ Buffer.from([0x41, 0xab]),
+ plistString("value"),
+ ]),
+ selection,
+ ),
+ ).toThrow("binary plist dictionary key is not a string");
+ });
+
it("reports a reference cycle as malformed, not as an oversized archive", () => {
expect(() =>
decodeKeyedArchiveBytes(keyedRoot([plistArray([8])]), selection),
diff --git a/src/evm/EvmoleInterfaceAdapter.test.ts b/src/evm/EvmoleInterfaceAdapter.test.ts
index a8b53f280..ea12143a1 100644
--- a/src/evm/EvmoleInterfaceAdapter.test.ts
+++ b/src/evm/EvmoleInterfaceAdapter.test.ts
@@ -61,6 +61,13 @@ it.each([
functions: [{ selector: "aabbccdd", bytecodeOffset: -1, dispatch: "abi" }],
},
{ metadata: {} },
+ {
+ metadata: {
+ bytecodeOffset: 1,
+ cborLength: 4,
+ entries: [{ key: "reported", value: { type: "integer", value: 1.5 } }],
+ },
+ },
])("rejects producer representations outside the selected profile", (raw) => {
expect(() => projectEvmoleInterface(raw)).toThrow();
});
diff --git a/src/evm/EvmoleInterfaceAdapter.ts b/src/evm/EvmoleInterfaceAdapter.ts
index da62d28b9..7ffd57853 100644
--- a/src/evm/EvmoleInterfaceAdapter.ts
+++ b/src/evm/EvmoleInterfaceAdapter.ts
@@ -9,7 +9,11 @@ const reportedMetadata = z.strictObject({
key: z.string(),
value: z.discriminatedUnion("type", [
z.strictObject({ type: z.literal("string"), value: z.string() }),
- z.strictObject({ type: z.literal("integer"), value: z.number() }),
+ z.strictObject({
+ type: z.literal("integer"),
+ // Reported integers can exceed the safe range; fractions still violate the tag.
+ value: z.number().refine(Number.isInteger, "Expected an integer"),
+ }),
z.strictObject({ type: z.literal("bytes"), value: z.string() }),
z.strictObject({ type: z.literal("bool"), value: z.boolean() }),
z.strictObject({ type: z.literal("undecoded"), value: z.string() }),