Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a data race and use-after-free when iterating over an :class:`io.StringIO` object while it is being concurrently mutated. The ``__next__`` method now properly acquires the object's lock.
14 changes: 13 additions & 1 deletion Modules/_io/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ _io_StringIO_readline_impl(stringio *self, Py_ssize_t size)
}

static PyObject *
stringio_iternext(PyObject *op)
stringio_iternext_lock_held(PyObject *op)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);

PyObject *line;
stringio *self = stringio_CAST(op);

Expand Down Expand Up @@ -444,6 +446,16 @@ stringio_iternext(PyObject *op)
return line;
}

static PyObject *
stringio_iternext(PyObject *op)
{
PyObject *ret;
Py_BEGIN_CRITICAL_SECTION(op);
ret = stringio_iternext_lock_held(op);
Py_END_CRITICAL_SECTION();
return ret;
}

/*[clinic input]
@critical_section
_io.StringIO.truncate
Expand Down
Loading