aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPeter Bierma <zintensitydev@gmail.com>2024-10-31 10:14:37 -0400
committerGitHub <noreply@github.com>2024-10-31 17:14:37 +0300
commit01415213d72504eafc159721a8f55d57b374fd9c (patch)
treeb807990380d31ed9096230f9e08de0228fc23e85
parent8c22eba877225ab29cd64672dcb97f09a5f7336f (diff)
downloadcpython-01415213d72504eafc159721a8f55d57b374fd9c.tar.gz
cpython-01415213d72504eafc159721a8f55d57b374fd9c.zip
gh-126223: Propagate unicode errors in `_interpreters.create()` (#126224)
Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
-rw-r--r--Lib/test/test_interpreters/test_api.py3
-rw-r--r--Misc/NEWS.d/next/Library/2024-10-30-23-42-44.gh-issue-126223.k2qooc.rst2
-rw-r--r--Modules/_interpretersmodule.c6
3 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_interpreters/test_api.py b/Lib/test/test_interpreters/test_api.py
index 5e3d7a052ba..a9befbba64d 100644
--- a/Lib/test/test_interpreters/test_api.py
+++ b/Lib/test/test_interpreters/test_api.py
@@ -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
index 00000000000..fee391c030b
--- /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 6f3392fe6ea..63f2bb38768 100644
--- a/Modules/_interpretersmodule.c
+++ b/Modules/_interpretersmodule.c
@@ -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;
}
}