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
+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() }),