https://github.com/python/cpython/commit/89664d4d482b9873b078df29654e4c3fa8ca066f
commit: 89664d4d482b9873b078df29654e4c3fa8ca066f
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-10-31T14:46:36Z
summary:

[3.13] gh-126223: Propagate unicode errors in `_interpreters.create()` 
(GH-126224) (#126242)

gh-126223: Propagate unicode errors in `_interpreters.create()` (GH-126224)
(cherry picked from commit 01415213d72504eafc159721a8f55d57b374fd9c)

Co-authored-by: Peter Bierma <[email protected]>
Co-authored-by: sobolevn <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst
M Lib/test/test_interpreters/test_api.py
M Modules/_interpretersmodule.c

diff --git a/Lib/test/test_interpreters/test_api.py 
b/Lib/test/test_interpreters/test_api.py
index 719c1c721cad7c..42819ae9b180b4 100644
--- a/Lib/test/test_interpreters/test_api.py
+++ b/Lib/test/test_interpreters/test_api.py
@@ -55,6 +55,9 @@ def test_in_main(self):
         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
index 00000000000000..fee391c030b941
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst
@@ -0,0 +1,2 @@
+Raise a :exc:`UnicodeEncodeError` instead of a :exc:`SystemError` upon
+calling :func:`!_interpreters.create` with an invalid Unicode character.
diff --git a/Modules/_interpretersmodule.c b/Modules/_interpretersmodule.c
index 86a4113dcc16f1..7933febf3cacfc 100644
--- a/Modules/_interpretersmodule.c
+++ b/Modules/_interpretersmodule.c
@@ -403,7 +403,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;
         }
     }

_______________________________________________
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