https://github.com/python/cpython/commit/5feedc759363dec4b9e2b0630bd57b8e4eba28f7
commit: 5feedc759363dec4b9e2b0630bd57b8e4eba28f7
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-18T17:47:39Z
summary:

[3.14] gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed 
(GH-146113) (#146130)

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 <[email protected]>

files:
M Modules/_csv.c

diff --git a/Modules/_csv.c b/Modules/_csv.c
index 1f41976e95fdb1..b994a42775178d 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -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,

_______________________________________________
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