Skip to content

Commit f693ea9

Browse files
vstinnermiss-islington
authored andcommitted
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 450e9ea commit f693ea9

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
@@ -302,8 +302,12 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
302302
static int
303303
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
304304
{
305-
if (src == NULL)
305+
if (src == NULL) {
306306
*target = PyUnicode_DecodeASCII(dflt, strlen(dflt), NULL);
307+
if (*target == NULL) {
308+
return -1;
309+
}
310+
}
307311
else {
308312
if (src == Py_None)
309313
*target = NULL;

0 commit comments

Comments
 (0)