]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126223: Propagate unicode errors in `_interpreters.create()` (#126224)
authorPeter Bierma <zintensitydev@gmail.com>
Thu, 31 Oct 2024 14:14:37 +0000 (10:14 -0400)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2024 14:14:37 +0000 (17:14 +0300)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/test/test_interpreters/test_api.py
Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst [new file with mode: 0644]
Modules/_interpretersmodule.c

index 5e3d7a052bae917aad000703a1b3b56df49e2582..a9befbba64daa049b6aae7160cb743da0240a854 100644 (file)
@@ -54,6 +54,9 @@ class CreateTests(TestBase):
         self.assertIsInstance(interp, interpreters.Interpreter)
         self.assertIn(interp, interpreters.list_all())
 
+        # GH-126221: Passing an invalid Unicode character used to cause a SystemError
+        self.assertRaises(UnicodeEncodeError, _interpreters.create, '\udc80')
+
     def test_in_thread(self):
         lock = threading.Lock()
         interp = None
diff --git a/Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst b/Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst
new file mode 100644 (file)
index 0000000..fee391c
--- /dev/null
@@ -0,0 +1,2 @@
+Raise a :exc:`UnicodeEncodeError` instead of a :exc:`SystemError` upon
+calling :func:`!_interpreters.create` with an invalid Unicode character.
index 6f3392fe6ea28ddca08d0114880de450bad31c43..63f2bb387685111158d3f5a1d7011e572899934e 100644 (file)
@@ -402,7 +402,11 @@ config_from_object(PyObject *configobj, PyInterpreterConfig *config)
         }
     }
     else if (PyUnicode_Check(configobj)) {
-        if (init_named_config(config, PyUnicode_AsUTF8(configobj)) < 0) {
+        const char *utf8name = PyUnicode_AsUTF8(configobj);
+        if (utf8name == NULL) {
+            return -1;
+        }
+        if (init_named_config(config, utf8name) < 0) {
             return -1;
         }
     }