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
6 changes: 6 additions & 0 deletions Lib/test/test_io/test_memoryio.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,12 @@ class CBytesIOTest(PyBytesIOTest):
ioclass = io.BytesIO
UnsupportedOperation = io.UnsupportedOperation

def test_readinto_overlapping_buffer(self):
with self.ioclass(b'abcd') as stream:
with stream.getbuffer()[1:] as target:
self.assertEqual(stream.readinto(target), 3)
self.assertEqual(stream.getvalue(), b'aabc')

def test_getstate(self):
memio = self.ioclass()
state = memio.__getstate__()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :class:`io.BytesIO` reads into overlapping views of the same buffer.
2 changes: 1 addition & 1 deletion Modules/_io/bytesio.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer)

assert(self->pos + len <= PY_SSIZE_T_MAX);
assert(len >= 0);
memcpy(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
memmove(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
self->pos += len;

return PyLong_FromSsize_t(len);
Expand Down
Loading