-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches #143043
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Modules/_io/textio.c
Outdated
|
|
||
| // gh-143007: PyNumber_Long can call arbitrary code through __int__ | ||
| // which may detach the underlying buffer. | ||
| if (self->detached) { |
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.
I think this isn't the right place to add the check, the _PyFile_Flush just before this could result in the same issue, and the cookie's buffer / decoding into it isn't what actually breaks (the buffer in this function is locally allocated, the cookie should be valid the whole time of this function).
I think this should do a CHECK_ATTACHED like check just before the res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(seek), posobj); as that's what is doing the self->buffer usage/call/dereference.
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.
Yes but it is my first solution
an rethink that we can forget add in the future in other place
CHECK_ATTACHED and check it in the middle of the code is not match its name
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.
changed back to the first way as you suggestion thank you
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
…/cpython into hy/close_issue_143007
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
this patch fix crash .TextIOWrapper.seek with a custom int method detaches
add
textiowrapper_parse_cookieinstead of check detect again to make the code clearTextIOWrapper.seekvia re-entrant__int__#143007