diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2017-04-19 19:09:56 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-19 19:09:56 (GMT) |
| commit | e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c (patch) | |
| tree | 4397f11f7bce21bf7e5be3dd8185eb5bf2d78c87 /Modules/_io/iobase.c | |
| parent | 49a905958ffc2fcd5d1d1a293ae453d45deeb884 (diff) | |
| download | cpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.zip cpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.tar.gz cpython-e63af29c87b44bb7ada5783cd0ff6ee6d4f9c17c.tar.bz2 | |
[3.5] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (#1182)
raised an error.
(cherry picked from commit bf623ae8843dc30b28c574bec8d29fc14be59d86)
(cherry picked from commit 680fea4067537a9b9c79aadd44a3a19e83cd2dbf)
Diffstat (limited to 'Modules/_io/iobase.c')
| -rw-r--r-- | Modules/_io/iobase.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 9c33565..9acd146 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -625,7 +625,8 @@ iobase_iternext(PyObject *self) if (line == NULL) return NULL; - if (PyObject_Size(line) == 0) { + if (PyObject_Size(line) <= 0) { + /* Error or empty */ Py_DECREF(line); return NULL; } @@ -676,6 +677,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) } while (1) { + Py_ssize_t line_length; PyObject *line = PyIter_Next(it); if (line == NULL) { if (PyErr_Occurred()) { @@ -689,11 +691,14 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) Py_DECREF(line); goto error; } - length += PyObject_Size(line); + line_length = PyObject_Size(line); Py_DECREF(line); - - if (length > hint) + if (line_length < 0) { + goto error; + } + if (line_length > hint - length) break; + length += line_length; } Py_DECREF(it); |
