-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
bpo-31243: fix PyArg_ParseTuple failure checks #3171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
14add40
d5575f6
99e8405
c8a21ba
a3a1212
f7f38c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix a crash in some methods of `io.TextIOWrapper`, when the decoder's state | ||
is invalid. Patch by Oren Milman. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1498,15 +1498,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; | ||
|
@@ -2384,8 +2392,8 @@ _io_TextIOWrapper_tell_impl(textio *self) | |
} \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add also an explicit check for a tuple. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that this should be fixed as part of bpo-28261, as bpo31243 is about PyArg_ParseTuple returning 0 or 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, this can be done in a separate PR. But in any case I think it is worth to add a NEWS.d entry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. of course, I would add it soon |
||
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; \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ISTM that this comment is wrong, but I didn't manage to find its origin (benjaminp created _textio.c with that comment in it (https://github.com/python/cpython/tree/4fa88fa0ba35e25ad9be66ebbdaba9aca553dc8b), but I don't know where it came from. BTW, the same comment can also be found in Lib/_pyio.py).
In addition, I am not familiar with the
io
module, so I am reluctant to remove this comment from here.what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think @benjaminp?