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

This commit is contained in:
morluto
2026-10-13 07:52:55 +08:00
parent d8ceb3f276
commit 9435c7aae2
4 changed files with 47 additions and 3 deletions
@@ -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) {
@@ -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),
+7
View File
@@ -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();
});
+5 -1
View File
@@ -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() }),