From: Victor Stinner Date: Wed, 18 Mar 2026 17:20:35 +0000 (+0100) Subject: gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (#146113) X-Git-Tag: v3.15.0a8~261 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=724c7c8146f44a7c737ec4588a1ee4b9db994f6f;p=thirdparty%2FPython%2Fcpython.git gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (#146113) The function can fail on a memory allocation failure. Bug reported by devdanzin. --- diff --git a/Modules/_csv.c b/Modules/_csv.c index c48f44c0f078..a3f840acbe8c 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,