From db0171297d14c71127b39915f2063561ae1b8a84 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:43:23 -0500 Subject: [PATCH] test(python): distinguish malformed marshal lengths from capacity failures (#12801) test(python): verify malformed signed marshal count defects --- src/python/PythonPycParser.test.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/python/PythonPycParser.test.ts b/src/python/PythonPycParser.test.ts index 27a0a97002..e07c2f6d25 100644 --- a/src/python/PythonPycParser.test.ts +++ b/src/python/PythonPycParser.test.ts @@ -573,12 +573,22 @@ it("decodes marshal strings with CPython surrogatepass rules", () => { ).toThrow(ParseFailureError); }); -it.each([0x73, 0x74, 0x75, 0x61, 0x41, 0x28, 0x5b, 0x3c, 0x3e])( +it.each([ + [0x73, "negative-string-length"], + [0x74, "negative-string-length"], + [0x75, "negative-string-length"], + [0x61, "negative-string-length"], + [0x41, "negative-string-length"], + [0x28, "negative-sequence-length"], + [0x5b, "negative-sequence-length"], + [0x3c, "negative-field"], + [0x3e, "negative-field"], +] as const)( "classifies a negative signed marshal count (tag %i) before applying limits", - (tag) => { + (tag, defect) => { expect(() => - parse(withConsts([Buffer.concat([Buffer.from([tag]), i32(-1)])])), - ).toThrow(ParseFailureError); + parse(withConsts([Buffer.from([tag, 0xff, 0xff, 0xff, 0xff])])), + ).toThrow(expect.objectContaining({ kind: "malformed", defect })); }, ); @@ -605,16 +615,6 @@ it("keeps signed zero and non-finite float and complex constants JSON-safe", () expect(JSON.parse(JSON.stringify(report))).toEqual(report); }); -it("truncates string previews without introducing a lone surrogate", () => { - const prefix = "x".repeat(79); - const report = parse( - withConsts([marshalUnicode(Buffer.from(`${prefix}😀tail`))]), - ); - expect(root(report).consts).toEqual([ - { kind: "str", bytes: 87, truncated: true, value: prefix }, - ]); -}); - it("accepts an empty co_filename", () => { const report = parse( Buffer.concat([