]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 18 Mar 2026 17:47:39 +0000 (18:47 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Mar 2026 17:47:39 +0000 (17:47 +0000)
gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (GH-146113)

The function can fail on a memory allocation failure.

Bug reported by devdanzin.
(cherry picked from commit 724c7c8146f44a7c737ec4588a1ee4b9db994f6f)

Co-authored-by: Victor Stinner <vstinner@python.org>
Modules/_csv.c

index 1f41976e95fdb1889ece2befa6c420c89c87ab63..b994a42775178daab05db1213e11f25289abedd1 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,