Skip to content

Commit 4dfcdbe

Browse files
[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 1795fcc) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 9b576f1 commit 4dfcdbe

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

Lib/test/test_type_comments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ def test_non_utf8_type_comment_with_ignore_cookie(self):
398398
with self.assertRaises(UnicodeDecodeError):
399399
_testcapi.Py_CompileStringExFlags(
400400
b"a=1 # type: \x80", "<test>", 256, flags)
401+
with self.assertRaises(UnicodeDecodeError):
402+
_testcapi.Py_CompileStringExFlags(
403+
b"def a(f=8, #type: \x80\n\x80", "<test>", 256, flags)
401404

402405
def test_func_type_input(self):
403406

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an unlikely crash when parsing an invalid type comments for function
2+
parameters. Found by OSS Fuzz in :oss-fuzz:`492782951`.

Parser/action_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ _PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
434434
return NULL;
435435
}
436436
a->arg = _PyPegen_add_type_comment_to_arg(p, arg, tc);
437+
if (!a->arg) {
438+
return NULL;
439+
}
437440
a->value = value;
438441
return a;
439442
}

0 commit comments

Comments
 (0)