@@ -531,7 +531,15 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
531531 _PyIO_str_getstate , NULL );
532532 if (state == NULL )
533533 return NULL ;
534- if (!PyArg_ParseTuple (state , "OK" , & buffer , & flag )) {
534+ if (!PyTuple_Check (state )) {
535+ PyErr_SetString (PyExc_TypeError ,
536+ "illegal decoder state" );
537+ Py_DECREF (state );
538+ return NULL ;
539+ }
540+ if (!PyArg_ParseTuple (state , "OK;illegal decoder state" ,
541+ & buffer , & flag ))
542+ {
535543 Py_DECREF (state );
536544 return NULL ;
537545 }
@@ -669,7 +677,7 @@ typedef struct
669677 written, or NULL */
670678 Py_ssize_t pending_bytes_count ;
671679
672- /* snapshot is either None , or a tuple (dec_flags, next_input) where
680+ /* snapshot is either NULL , or a tuple (dec_flags, next_input) where
673681 * dec_flags is the second (integer) item of the decoder state and
674682 * next_input is the chunk of input bytes that comes next after the
675683 * snapshot point. We use this to reconstruct decoder states in tell().
@@ -2351,6 +2359,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
23512359 goto fail ;
23522360
23532361 /* Skip backward to the snapshot point (see _read_chunk). */
2362+ assert (PyTuple_Check (self -> snapshot ));
23542363 if (!PyArg_ParseTuple (self -> snapshot , "iO" , & cookie .dec_flags , & next_input ))
23552364 goto fail ;
23562365
@@ -2378,7 +2387,15 @@ _io_TextIOWrapper_tell_impl(textio *self)
23782387 _PyIO_str_getstate, NULL); \
23792388 if (_state == NULL) \
23802389 goto fail; \
2381- if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \
2390+ if (!PyTuple_Check(_state)) { \
2391+ PyErr_SetString(PyExc_TypeError, \
2392+ "illegal decoder state"); \
2393+ Py_DECREF(_state); \
2394+ goto fail; \
2395+ } \
2396+ if (!PyArg_ParseTuple(_state, "Oi;illegal decoder state", \
2397+ &dec_buffer, &dec_flags)) \
2398+ { \
23822399 Py_DECREF(_state); \
23832400 goto fail; \
23842401 } \
0 commit comments