[3.13] gh-148157: Check for _PyPegen_add_type_comment_to_arg fail in _PyPegen_name_default_pair (GH-148158) (#148163)

(cherry picked from commit 1795fccfbc)

Co-authored-by: Stan Ulbrych <stan@python.org>
This commit is contained in:
Miss Islington (bot)
2026-04-06 14:13:32 +02:00
committed by GitHub
parent 9b576f14bf
commit 4dfcdbe22c
3 changed files with 8 additions and 0 deletions
+3
View File
@@ -398,6 +398,9 @@ class TypeCommentTests(unittest.TestCase):
with self.assertRaises(UnicodeDecodeError):
_testcapi.Py_CompileStringExFlags(
b"a=1 # type: \x80", "<test>", 256, flags)
with self.assertRaises(UnicodeDecodeError):
_testcapi.Py_CompileStringExFlags(
b"def a(f=8, #type: \x80\n\x80", "<test>", 256, flags)
def test_func_type_input(self):
@@ -0,0 +1,2 @@
Fix an unlikely crash when parsing an invalid type comments for function
parameters. Found by OSS Fuzz in :oss-fuzz:`492782951`.
+3
View File
@@ -434,6 +434,9 @@ _PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
return NULL;
}
a->arg = _PyPegen_add_type_comment_to_arg(p, arg, tc);
if (!a->arg) {
return NULL;
}
a->value = value;
return a;
}