]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-148157: Check for `_PyPegen_add_type_comment_to_arg` fail in `_PyPegen_name_defau...
authorStan Ulbrych <stan@python.org>
Mon, 6 Apr 2026 11:56:36 +0000 (12:56 +0100)
committerGitHub <noreply@github.com>
Mon, 6 Apr 2026 11:56:36 +0000 (12:56 +0100)
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 dd2e67841651d911b788d2e29c0bd07e7b28575c..d827ac271085bddd25a75f17b3759b421cf21a0d 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 1f5b6220ba1baa5999a361d90e99ae944a69088b..5e52bb838719046485bde7d88f37d9a83e6a6d7d 100644 (file)
@@ -435,6 +435,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;
 }