summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-08-29 08:58:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-08-29 08:58:27 (GMT)
commitba7d7365215d791025d1efd25393c91404f2cfc8 (patch)
tree8ba0a3b1944172f450f0d76f588bb106dd50e174 /Modules/_io
parente9d978fd1bc122395efc91a82b16b2c4b968441d (diff)
downloadcpython-ba7d7365215d791025d1efd25393c91404f2cfc8.zip
cpython-ba7d7365215d791025d1efd25393c91404f2cfc8.tar.gz
cpython-ba7d7365215d791025d1efd25393c91404f2cfc8.tar.bz2
bpo-31243: Fixed PyArg_ParseTuple failure checks. (#3171)
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/textio.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 402f743..9b7334d 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1513,15 +1513,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;
@@ -2408,8 +2416,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; \