From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:45:47 +0000 (+0100) Subject: [3.13] gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (GH... X-Git-Tag: v3.13.13~78 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7d7e1c1a023c0b98ffb8e383fa03934bc834d65;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed (GH-146113) (#146131) 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 --- diff --git a/Modules/_csv.c b/Modules/_csv.c index aea071cc1433..0b7ff2575fcf 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -302,8 +302,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 (src == Py_None) *target = NULL;