FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches by yihong0618 · Pull Request #143043 · python/cpython · GitHub

Repository navigation

gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches - #143043

Closed
yihong0618 wants to merge 6 commits into
python:mainfrom
yihong0618:hy/close_issue_143007
Closed

yihong0618 wants to merge 6 commits into
python:mainfrom
yihong0618:hy/close_issue_143007

Conversation

yihong0618 commented Dec 21, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

this patch fix crash .TextIOWrapper.seek with a custom int method detaches

add textiowrapper_parse_cookie instead of check detect again to make the code clear

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
yihong0618 changed the title fix: crash .TextIOWrapper.seek with a custom __int__ method detaches gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches Dec 21, 2025
Comment thread Modules/_io/textio.c Outdated

// gh-143007: PyNumber_Long can call arbitrary code through __int__
// which may detach the underlying buffer.
if (self->detached) {

cmaloney Dec 21, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Signed-off-by: yihong0618 <zouzou0208@gmail.com>

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label May 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR! A more general fix was merged in #145957 as part of gh-143008.

cmaloney closed this Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL