Skip to content

Commit 7a09d55

Browse files
committed
gh-146093: Fix csv _set_str(): check if PyUnicode_DecodeASCII() failed
The function can fail on a memory allocation failure. Bug reported by devdanzin.
1 parent 3b06d68 commit 7a09d55

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)