diff options
author | Oren Milman <orenmn@gmail.com> | 2017-08-29 12:43:32 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-08-29 12:43:32 (GMT) |
commit | c7750c2a3af014a5b742d0159d8957ea95b6c221 (patch) | |
tree | 164a30ef28a8ca03a797705c79659168db2211ef /Modules/_io | |
parent | 83e5c888fff2bf3663952b2bfd3a3ee6c20386ef (diff) | |
download | cpython-c7750c2a3af014a5b742d0159d8957ea95b6c221.zip cpython-c7750c2a3af014a5b742d0159d8957ea95b6c221.tar.gz cpython-c7750c2a3af014a5b742d0159d8957ea95b6c221.tar.bz2 |
[3.6] bpo-31243: Fixed PyArg_ParseTuple failure checks. (GH-3171) (#3233)
(cherry picked from commit ba7d7365215d791025d1efd25393c91404f2cfc8)
Diffstat (limited to 'Modules/_io')
-rw-r--r-- | Modules/_io/textio.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 801bb17..588c697 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1457,15 +1457,23 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint) /* Given this, we know there was a valid snapshot point * len(dec_buffer) bytes ago with decoder state (b'', dec_flags). */ - if (PyArg_ParseTuple(state, "OO", &dec_buffer, &dec_flags) < 0) { + if (!PyTuple_Check(state)) { + PyErr_SetString(PyExc_TypeError, + "illegal decoder state"); + Py_DECREF(state); + return -1; + } + if (!PyArg_ParseTuple(state, + "OO;illegal decoder state", &dec_buffer, &dec_flags)) + { Py_DECREF(state); return -1; } if (!PyBytes_Check(dec_buffer)) { PyErr_Format(PyExc_TypeError, - "decoder getstate() should have returned a bytes " - "object, not '%.200s'", + "illegal decoder state: the first item should be a " + "bytes object, not '%.200s'", Py_TYPE(dec_buffer)->tp_name); Py_DECREF(state); return -1; @@ -2349,8 +2357,8 @@ _io_TextIOWrapper_tell_impl(textio *self) } \ if (!PyBytes_Check(dec_buffer)) { \ PyErr_Format(PyExc_TypeError, \ - "decoder getstate() should have returned a bytes " \ - "object, not '%.200s'", \ + "illegal decoder state: the first item should be a " \ + "bytes object, not '%.200s'", \ Py_TYPE(dec_buffer)->tp_name); \ Py_DECREF(_state); \ goto fail; \ |