]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (#146113)
authorVictor Stinner <vstinner@python.org>
Wed, 18 Mar 2026 17:20:35 +0000 (18:20 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Mar 2026 17:20:35 +0000 (18:20 +0100)
The function can fail on a memory allocation failure.

Bug reported by devdanzin.

Modules/_csv.c

index c48f44c0f07867b6e1f0a889e5b4a6884357d594..a3f840acbe8c0b7453494a5a8fad3bd3ba57adf7 100644 (file)
@@ -315,8 +315,12 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
 static int
 _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
 {
-    if (src == NULL)
+    if (src == NULL) {
         *target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL);
+        if (*target == NULL) {
+            return -1;
+        }
+    }
     else {
         if (!PyUnicode_Check(src)) {
             PyErr_Format(PyExc_TypeError,