Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 008d88b

Browse files
Issue #24009: Got rid of using rare "y#" format unit in TextIOWrapper.tell().
Parsed value should be bytes, not general robuffer, this is required in other places.
1 parent 9749b5a commit 008d88b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Modules/_io/textio.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,6 @@ _io_TextIOWrapper_tell_impl(textio *self)
22622262
Py_ssize_t skip_bytes, skip_back;
22632263
PyObject *saved_state = NULL;
22642264
char *input, *input_end;
2265-
char *dec_buffer;
22662265
Py_ssize_t dec_buffer_len;
22672266
int dec_flags;
22682267

@@ -2327,14 +2326,24 @@ _io_TextIOWrapper_tell_impl(textio *self)
23272326
goto fail;
23282327

23292328
#define DECODER_GETSTATE() do { \
2329+
PyObject *dec_buffer; \
23302330
PyObject *_state = PyObject_CallMethodObjArgs(self->decoder, \
23312331
_PyIO_str_getstate, NULL); \
23322332
if (_state == NULL) \
23332333
goto fail; \
2334-
if (!PyArg_ParseTuple(_state, "y#i", &dec_buffer, &dec_buffer_len, &dec_flags)) { \
2334+
if (!PyArg_ParseTuple(_state, "Oi", &dec_buffer, &dec_flags)) { \
23352335
Py_DECREF(_state); \
23362336
goto fail; \
23372337
} \
2338+
if (!PyBytes_Check(dec_buffer)) { \
2339+
PyErr_Format(PyExc_TypeError, \
2340+
"decoder getstate() should have returned a bytes " \
2341+
"object, not '%.200s'", \
2342+
Py_TYPE(dec_buffer)->tp_name); \
2343+
Py_DECREF(_state); \
2344+
goto fail; \
2345+
} \
2346+
dec_buffer_len = PyBytes_GET_SIZE(dec_buffer); \
23382347
Py_DECREF(_state); \
23392348
} while (0)
23402349

0 commit comments

Comments
 (0)