Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions Lib/test/test_io/test_memoryio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pickle
import sys
import weakref
from test.support.import_helper import import_module

class IntLike:
def __init__(self, num):
Expand Down Expand Up @@ -552,6 +553,17 @@ def test_relative_seek(self):
memio.seek(1, 1)
self.assertEqual(memio.read(), buf[1:])

def test_issue141311(self):
_testcapi = import_module("_testcapi")

memio = self.ioclass()
# Seek allows PY_SSIZE_T_MAX, read handle that.
# Past end of buffer read should always return 0 (EOF).
self.assertEqual(_testcapi.PY_SSIZE_T_MAX,
memio.seek(_testcapi.PY_SSIZE_T_MAX))
buf = bytearray(2)
self.assertEqual(0, memio.readinto(buf))

def test_unicode(self):
memio = self.ioclass()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix assertion failure in :class:`io.BytesIO` implementation of
:func:`~io.BufferedIOBase.readinto` when the current offset is at the max
offset and readinto is called.
5 changes: 3 additions & 2 deletions Modules/_io/bytesio.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,9 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer)
n = self->string_size - self->pos;
if (len > n) {
len = n;
if (len < 0)
len = 0;
if (len < 0) {
return PyLong_FromSsize_t(0);
}
}

assert(self->pos + len < PY_SSIZE_T_MAX);
Expand Down
Loading