]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-148157: Check for `_PyPegen_add_type_comment_to_arg` fail in `_PyPegen_name...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 6 Apr 2026 12:13:32 +0000 (14:13 +0200)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2026 12:13:32 +0000 (12:13 +0000)
(cherry picked from commit 1795fccfbc7ccb89ead5c529b2f55f54622d1314)

Co-authored-by: Stan Ulbrych <stan@python.org>
Lib/test/test_type_comments.py
Misc/NEWS.d/next/Core_and_Builtins/2026-04-06-11-15-46.gh-issue-148157.JFnZDn.rst [new file with mode: 0644]
Parser/action_helpers.c

index feb415bfc2a9d13ec3f83294d69d66bc908da7c4..063de76e974739cac5df7913affe83bbb6de4e42 100644 (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):
 
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 (file)
index 0000000..6565291
--- /dev/null
@@ -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`.
index 6f841ef2e4f9c3b214c73182d2eb6af6b3f9e180..dee534904cd895d3ed1c13b23da9b4934c2860a4 100644 (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;
 }