Skip to content

Commit 5feedc7

Browse files
[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 724c7c8) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 3ebf54e commit 5feedc7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Modules/_csv.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,12 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
315315
static int
316316
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
317317
{
318-
if (src == NULL)
318+
if (src == NULL) {
319319
*target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL);
320+
if (*target == NULL) {
321+
return -1;
322+
}
323+
}
320324
else {
321325
if (!PyUnicode_Check(src)) {
322326
PyErr_Format(PyExc_TypeError,

0 commit comments

Comments
 (0)