René's URL Explorer Experiment


Title: Null pointer dereference in `TextIOWrapper.seek` via re-entrant `__int__` · Issue #143007 · python/cpython · GitHub

Open Graph Title: Null pointer dereference in `TextIOWrapper.seek` via re-entrant `__int__` · Issue #143007 · python/cpython

X Title: Null pointer dereference in `TextIOWrapper.seek` via re-entrant `__int__` · Issue #143007 · python/cpython

Description: What happened? A crafted integer subclass overrides __int__ so when TextIOWrapper.seek converts the cookie with PyNumber_Long it detaches the wrapper and frees the buffer, yet the seek logic continues with the original self->buffer, lead...

Open Graph Description: What happened? A crafted integer subclass overrides __int__ so when TextIOWrapper.seek converts the cookie with PyNumber_Long it detaches the wrapper and frees the buffer, yet the seek logic contin...

X Description: What happened? A crafted integer subclass overrides __int__ so when TextIOWrapper.seek converts the cookie with PyNumber_Long it detaches the wrapper and frees the buffer, yet the seek logic contin...

Opengraph URL: https://github.com/python/cpython/issues/143007

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Null pointer dereference in `TextIOWrapper.seek` via re-entrant `__int__`","articleBody":"### What happened?\n\nA crafted integer subclass overrides `__int__` so when `TextIOWrapper.seek` converts the cookie with `PyNumber_Long` it detaches the wrapper and frees the buffer, yet the seek logic continues with the original `self->buffer`, leading `_io_TextIOWrapper_seek_impl` to call a method on a NULL pointer and crash the interpreter.\n\n**Proof of Concept:**\n```python\nimport io\n\nwrapper = io.TextIOWrapper(io.BytesIO(b\"x\"))\n\nclass Cookie(int):\n    def __new__(cls, wrapper):\n        obj = int.__new__(cls, 0)\n        obj.wrapper = wrapper\n        return obj\n    def __int__(self):\n        self.wrapper.detach()\n        return 0\n\nwrapper.seek(Cookie(wrapper), io.SEEK_SET)\n```\n\n\n**Affected Versions:**\n\u003cdetails>\n\n| Python Version | Status | Exit Code |\n|---|---|---|\n| `Python 3.9.24+ (heads/3.9:111bbc15b26, Oct 28 2025, 16:51:20) ` | ASAN | 1 |\n| `Python 3.10.19+ (heads/3.10:014261980b1, Oct 28 2025, 16:52:08) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.11.14+ (heads/3.11:88f3f5b5f11, Oct 28 2025, 16:53:08) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.12.12+ (heads/3.12:8cb2092bd8c, Oct 28 2025, 16:54:14) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.13.9+ (heads/3.13:9c8eade20c6, Oct 28 2025, 16:55:18) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.14.0+ (heads/3.14:2e216728038, Oct 28 2025, 16:56:16) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.15.0a1+ (heads/main:f5394c257ce, Oct 28 2025, 16:57:16) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n\n\u003c/details>\n\n**Vulnerable Code:**\n\u003cdetails>\n\n```c\nstatic int\ntextiowrapper_parse_cookie(cookie_type *cookie, PyObject *cookieObj)\n{\n    unsigned char buffer[COOKIE_BUF_LEN];\n    PyLongObject *cookieLong = (PyLongObject *)PyNumber_Long(cookieObj);\n    if (cookieLong == NULL)\n        return -1;\n\n    if (_PyLong_AsByteArray(cookieLong, buffer, sizeof(buffer),\n                            PY_LITTLE_ENDIAN, 0, 1) \u003c 0) {\n        Py_DECREF(cookieLong);\n        return -1;\n    }\n    Py_DECREF(cookieLong);\n\n    memcpy(&cookie->start_pos, buffer + OFF_START_POS, sizeof(cookie->start_pos));\n    memcpy(&cookie->dec_flags, buffer + OFF_DEC_FLAGS, sizeof(cookie->dec_flags));\n    memcpy(&cookie->bytes_to_feed, buffer + OFF_BYTES_TO_FEED, sizeof(cookie->bytes_to_feed));\n    memcpy(&cookie->chars_to_skip, buffer + OFF_CHARS_TO_SKIP, sizeof(cookie->chars_to_skip));\n    memcpy(&cookie->need_eof, buffer + OFF_NEED_EOF, sizeof(cookie->need_eof));\n\n    return 0;\n}\n\nstatic PyObject *\n_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)\n/*[clinic end generated code: output=0a15679764e2d04d input=4bea78698be23d7e]*/\n{\n    PyObject *posobj;\n    cookie_type cookie;\n    PyObject *res;\n    int cmp;\n    PyObject *snapshot;\n\n    CHECK_ATTACHED(self);\n    CHECK_CLOSED(self);\n\n    Py_INCREF(cookieObj);\n\n    if (!self->seekable) {\n        _unsupported(self->state, \"underlying stream is not seekable\");\n        goto fail;\n    }\n\n    /* ... */\n\n    /* The strategy of seek() is to go back to the safe start point\n     * and replay the effect of read(chars_to_skip) from there.\n     */\n    if (textiowrapper_parse_cookie(&cookie, cookieObj) \u003c 0)\n        goto fail;\n\n    /* Seek back to the safe start point. */\n    posobj = PyLong_FromOff_t(cookie.start_pos);\n    if (posobj == NULL)\n        goto fail;\n\n    // self->buf has been set to null\n    res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(seek), posobj);\n```\n\n\u003c/details>\n\n**Sanitizer Output:**\n\u003cdetails>\n\n```\n=================================================================\n==1652913==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x5e52803ff39a bp 0x7fff1072a2c0 sp 0x7fff1072a200 T0)\n==1652913==The signal is caused by a READ memory access.\n==1652913==Hint: address points to the zero page.\n    #0 0x5e52803ff39a in _Py_TYPE Include/object.h:277\n    #1 0x5e52803ff39a in _PyObject_GetMethodStackRef Objects/object.c:1698\n    #2 0x5e528033f796 in PyObject_VectorcallMethod Objects/call.c:840\n    #3 0x5e52807f39a2 in PyObject_CallMethodOneArg Include/cpython/abstract.h:74\n    #4 0x5e52807fb66b in _io_TextIOWrapper_seek_impl Modules/_io/textio.c:2647\n    #5 0x5e52807fbe97 in _io_TextIOWrapper_seek Modules/_io/clinic/textio.c.h:938\n    #6 0x5e528035d6ed in method_vectorcall_FASTCALL Objects/descrobject.c:402\n    #7 0x5e528033de7f in _PyObject_VectorcallTstate Include/internal/pycore_call.h:169\n    #8 0x5e528033df72 in PyObject_Vectorcall Objects/call.c:327\n    #9 0x5e52805bc056 in _PyEval_EvalFrameDefault Python/generated_cases.c.h:1620\n    #10 0x5e52805ffe54 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:121\n    #11 0x5e5280600148 in _PyEval_Vector Python/ceval.c:2001\n    #12 0x5e52806003f8 in PyEval_EvalCode Python/ceval.c:884\n    #13 0x5e52806f7507 in run_eval_code_obj Python/pythonrun.c:1365\n    #14 0x5e52806f7723 in run_mod Python/pythonrun.c:1459\n    #15 0x5e52806f857a in pyrun_file Python/pythonrun.c:1293\n    #16 0x5e52806fb220 in _PyRun_SimpleFileObject Python/pythonrun.c:521\n    #17 0x5e52806fb4f6 in _PyRun_AnyFileObject Python/pythonrun.c:81\n    #18 0x5e528074c74d in pymain_run_file_obj Modules/main.c:410\n    #19 0x5e528074c9b4 in pymain_run_file Modules/main.c:429\n    #20 0x5e528074e1b2 in pymain_run_python Modules/main.c:691\n    #21 0x5e528074e842 in Py_RunMain Modules/main.c:772\n    #22 0x5e528074ea2e in pymain_main Modules/main.c:802\n    #23 0x5e528074edb3 in Py_BytesMain Modules/main.c:826\n    #24 0x5e52801d2645 in main Programs/python.c:15\n    #25 0x7642c742a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58\n    #26 0x7642c742a28a in __libc_start_main_impl ../csu/libc-start.c:360\n    #27 0x5e52801d2574 in _start (/home/jackfromeast/Desktop/entropy/targets/grammar-afl++-latest/targets/cpython/python+0x2dd574) (BuildId: 202d5dbb945f6d5f5a66ad50e2688d56affd6ecb)\n\nAddressSanitizer can not provide additional info.\nSUMMARY: AddressSanitizer: SEGV Include/object.h:277 in _Py_TYPE\n==1652913==ABORTING\n```\n\n\u003c/details>\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-143043\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jackfromeast","@type":"Person","name":"jackfromeast"},"datePublished":"2025-12-20T04:16:31Z","url":"https://github.com/python/cpython/issues/143007"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f2170c4e-193b-a6f5-71b8-73f0cec3b9e8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idACE2:25CD63:3C0D4:4B73E:6B01F7E6
html-safe-nonce05d4c8580bee2372cb47cf4bc756d3290df2d2480767fcd30881a48384c3c52c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0UyOjI1Q0Q2MzozQzBENDo0QjczRTo2QjAxRjdFNiIsInZpc2l0b3JfaWQiOiIyNjYxNDk4MzQ3ODY4NzgwNTE4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac3ae6b7204c8889f9d7184df9098bbda32763a4d6d4255d369520ce8af2a7bdd9
hovercard-subject-tagissue:3749522864
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/143007/issue_layout
twitter:imagehttps://opengraph.githubassets.com/38dec5c0153449fd9acf7010fd8aef9afc7b18976de6ce24db83725b88ac5ee7/python/cpython/issues/143007
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/38dec5c0153449fd9acf7010fd8aef9afc7b18976de6ce24db83725b88ac5ee7/python/cpython/issues/143007
og:image:altWhat happened? A crafted integer subclass overrides __int__ so when TextIOWrapper.seek converts the cookie with PyNumber_Long it detaches the wrapper and frees the buffer, yet the seek logic contin...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejackfromeast
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/143007#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F143007
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F143007
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/143007
Reloadhttps://github.com/python/cpython/issues/143007
Reloadhttps://github.com/python/cpython/issues/143007
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/143007
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/143007
Null pointer dereference in TextIOWrapper.seek via re-entrant __int__https://github.com/python/cpython/issues/143007#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/jackfromeast
jackfromeasthttps://github.com/jackfromeast
on Dec 20, 2025https://github.com/python/cpython/issues/143007#issue-3749522864
gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches #143043https://github.com/python/cpython/pull/143043
https://github.com/yihong0618
yihong0618https://github.com/yihong0618
on Dec 20, 2025https://github.com/python/cpython/issues/143007#issuecomment-3677412419
#143008 (comment)https://github.com/python/cpython/issues/143008#issuecomment-3677398247
@jackfromeasthttps://github.com/jackfromeast
StanFromIrelandhttps://github.com/StanFromIreland
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
on Dec 20, 2025https://github.com/python/cpython/issues/143007#event-21683883453
picnixzhttps://github.com/picnixz
gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches #143043https://github.com/python/cpython/pull/143043
on Jan 1, 2026https://github.com/python/cpython/issues/143007#event-21817977919
https://github.com/picnixz
picnixzhttps://github.com/picnixz
on Jan 1, 2026https://github.com/python/cpython/issues/143007#issuecomment-3703618326
picnixzhttps://github.com/picnixz
gh-143007: fix crash .TextIOWrapper.seek with a custom __int__ method detaches #143043https://github.com/python/cpython/pull/143043
on Jan 1, 2026https://github.com/python/cpython/issues/143007#event-21817982315
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Jun 10, 2026https://github.com/python/cpython/issues/143007#issuecomment-4673313366
gh-143008https://github.com/python/cpython/issues/143008
@jackfromeasthttps://github.com/jackfromeast
cmaloneyhttps://github.com/cmaloney
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jun 10, 2026https://github.com/python/cpython/issues/143007#event-26589697671
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/143007
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/143007
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.