https://github.com/python/cpython/commit/4dfcdbe22c1901221faf11444a7e8a7bc4ab4c16
commit: 4dfcdbe22c1901221faf11444a7e8a7bc4ab4c16
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-04-06T12:13:32Z
summary:

[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 1795fccfbc7ccb89ead5c529b2f55f54622d1314)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-04-06-11-15-46.gh-issue-148157.JFnZDn.rst
M Lib/test/test_type_comments.py
M Parser/action_helpers.c

diff --git a/Lib/test/test_type_comments.py b/Lib/test/test_type_comments.py
index feb415bfc2a9d1..063de76e974739 100644
--- a/Lib/test/test_type_comments.py
+++ b/Lib/test/test_type_comments.py
@@ -398,6 +398,9 @@ def test_non_utf8_type_comment_with_ignore_cookie(self):
         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):
 
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-06-11-15-46.gh-issue-148157.JFnZDn.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-06-11-15-46.gh-issue-148157.JFnZDn.rst
new file mode 100644
index 00000000000000..6565291eb998ed
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-06-11-15-46.gh-issue-148157.JFnZDn.rst
@@ -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`.
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c
index 6f841ef2e4f9c3..dee534904cd895 100644
--- a/Parser/action_helpers.c
+++ b/Parser/action_helpers.c
@@ -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;
 }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to