mirror of https://github.com/python/cpython.git
Issue #18025: Fixed a segfault in io.BufferedIOBase.readinto() when raw
stream's read() returns more bytes than requested.
This commit is contained in:
parent
12516e2c1b
commit
37a79a12d1
|
@ -3019,6 +3019,15 @@ def test_open_allargs(self):
|
||||||
class CMiscIOTest(MiscIOTest):
|
class CMiscIOTest(MiscIOTest):
|
||||||
io = io
|
io = io
|
||||||
|
|
||||||
|
def test_readinto_buffer_overflow(self):
|
||||||
|
# Issue #18025
|
||||||
|
class BadReader(self.io.BufferedIOBase):
|
||||||
|
def read(self, n=-1):
|
||||||
|
return b'x' * 10**6
|
||||||
|
bufio = BadReader()
|
||||||
|
b = bytearray(2)
|
||||||
|
self.assertRaises(ValueError, bufio.readinto, b)
|
||||||
|
|
||||||
class PyMiscIOTest(MiscIOTest):
|
class PyMiscIOTest(MiscIOTest):
|
||||||
io = pyio
|
io = pyio
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #18025: Fixed a segfault in io.BufferedIOBase.readinto() when raw
|
||||||
|
stream's read() returns more bytes than requested.
|
||||||
|
|
||||||
- Issue #18011: base64.b32decode() now raises a binascii.Error if there are
|
- Issue #18011: base64.b32decode() now raises a binascii.Error if there are
|
||||||
non-alphabet characters present in the input string to conform a docstring.
|
non-alphabet characters present in the input string to conform a docstring.
|
||||||
Updated the module documentation.
|
Updated the module documentation.
|
||||||
|
|
|
@ -69,6 +69,14 @@ bufferediobase_readinto(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
len = Py_SIZE(data);
|
len = Py_SIZE(data);
|
||||||
|
if (len > buf.len) {
|
||||||
|
PyErr_Format(PyExc_ValueError,
|
||||||
|
"read() returned too much data: "
|
||||||
|
"%zd bytes requested, %zd returned",
|
||||||
|
buf.len, len);
|
||||||
|
Py_DECREF(data);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
memcpy(buf.buf, PyBytes_AS_STRING(data), len);
|
memcpy(buf.buf, PyBytes_AS_STRING(data), len);
|
||||||
|
|
||||||
PyBuffer_Release(&buf);
|
PyBuffer_Release(&buf);
|
||||||
|
|
Loading…
Reference in New Issue