René's URL Explorer Experiment


Title: Null pointer dereference in `TextIOWrapper.close()` via re-entrant `closed` property that detaches `buffer` · Issue #142594 · python/cpython · GitHub

Open Graph Title: Null pointer dereference in `TextIOWrapper.close()` via re-entrant `closed` property that detaches `buffer` · Issue #142594 · python/cpython

X Title: Null pointer dereference in `TextIOWrapper.close()` via re-entrant `closed` property that detaches `buffer` · Issue #142594 · python/cpython

Description: What happened? TextIOWrapper.close() queries the stream’s closed property. A user-defined RawIOBase.closed can re-enter and call wrapper.detach(), clearing self->buffer. The function then continues and calls self->buffer.close() on a NUL...

Open Graph Description: What happened? TextIOWrapper.close() queries the stream’s closed property. A user-defined RawIOBase.closed can re-enter and call wrapper.detach(), clearing self->buffer. The function then continues...

X Description: What happened? TextIOWrapper.close() queries the stream’s closed property. A user-defined RawIOBase.closed can re-enter and call wrapper.detach(), clearing self->buffer. The function then contin...

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

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.close()` via re-entrant `closed` property that detaches `buffer`","articleBody":"### What happened?\n\n`TextIOWrapper.close()` queries the stream’s `closed` property. A user-defined `RawIOBase.closed` can re-enter and call `wrapper.detach()`, clearing `self->buffer`. The function then continues and calls `self->buffer.close()` on a NULL pointer, leading to a null-pointer dereference in `_PyObject_GetMethod`/`_Py_TYPE`.\n\n**Proof of Concept:**\n```python\nimport io\n\nclass EvilBuffer(io.RawIOBase):\n    def __init__(self):\n        super().__init__()\n        self.wrapper = None\n        self.detached = False\n\n    @property\n    def closed(self):\n        if self.wrapper is not None and not self.detached:\n            self.detached = True\n            self.wrapper.detach()\n        return False\n\nraw = EvilBuffer()\nwrapper = io.TextIOWrapper(raw)\nraw.wrapper = wrapper\nwrapper.close()\n```\n\n\n**Affected Versions:**\n| Python Version | Status | Exit Code |\n|---|---|---|\n| `Python 3.9.24+ (heads/3.9:9c4638d, Oct 17 2025, 11:19:30) ` | ASAN | 1 |\n| `Python 3.10.19+ (heads/3.10:0142619, Oct 17 2025, 11:20:05) [GCC 13.3.0]` | ASAN | 1 |\n| `Python 3.11.14+ (heads/3.11:88f3f5b, Oct 17 2025, 11:20:44) [GCC 13.3.0]` | ASAN | 1 |\n| `Python 3.12.12+ (heads/3.12:8cb2092, Oct 17 2025, 11:21:35) [GCC 13.3.0]` | ASAN | 1 |\n| `Python 3.13.9+ (heads/3.13:0760a57, Oct 17 2025, 11:22:25) [GCC 13.3.0]` | ASAN | 1 |\n| `Python 3.14.0+ (heads/3.14:889e918, Oct 17 2025, 11:23:02) [GCC 13.3.0]` | ASAN | 1 |\n| `Python 3.15.0a1+ (heads/main:fbf0843, Oct 17 2025, 11:23:37) [GCC 13.3.0]` | ASAN | 1 |\n\n**Related Code Snippet**\n```python\n/*[clinic input]\n@critical_section\n_io.TextIOWrapper.close\n[clinic start generated code]*/\n\nstatic PyObject *\n_io_TextIOWrapper_close_impl(textio *self)\n/*[clinic end generated code: output=056ccf8b4876e4f4 input=8e12d7079d5ac5c1]*/\n{\n    PyObject *res;\n    int r;\n    CHECK_ATTACHED(self);\n\t\t\n    // Bug: Re-enter the closed property method which detached the textio buffer \n    res = _io_TextIOWrapper_closed_get_impl(self);\n    if (res == NULL)\n        return NULL;\n    r = PyObject_IsTrue(res);\n    Py_DECREF(res);\n    if (r \u003c 0)\n        return NULL;\n\n    if (r > 0) {\n        Py_RETURN_NONE; /* stream already closed */\n    }\n    else {\n        PyObject *exc = NULL;\n        if (self->finalizing) {\n            res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(_dealloc_warn),\n                                            (PyObject *)self);\n            if (res) {\n                Py_DECREF(res);\n            }\n            else {\n                PyErr_Clear();\n            }\n        }\n        if (_PyFile_Flush((PyObject *)self) \u003c 0) {\n            exc = PyErr_GetRaisedException();\n        }\n\t\t\t\t\n\t\t// Crash: self->buffer=0x0 after detached.\n        res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(close));\n        if (exc != NULL) {\n            _PyErr_ChainExceptions1(exc);\n            Py_CLEAR(res);\n        }\n        return res;\n    }\n}\n```\n\n**Sanitizer Output:**\n```\n=================================================================\n==1558952==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000008 (pc 0x64c4d0fea39a bp 0x7ffe22fcb5f0 sp 0x7ffe22fcb530 T0)\n==1558952==The signal is caused by a READ memory access.\n==1558952==Hint: address points to the zero page.\n    #0 0x64c4d0fea39a in _Py_TYPE Include/object.h:277\n    #1 0x64c4d0fea39a in _PyObject_GetMethodStackRef Objects/object.c:1698\n    #2 0x64c4d0f2a796 in PyObject_VectorcallMethod Objects/call.c:840\n    #3 0x64c4d13e717d in PyObject_CallMethodNoArgs Include/cpython/abstract.h:65\n    #4 0x64c4d13e717d in _io_TextIOWrapper_close_impl Modules/_io/textio.c:3169\n    #5 0x64c4d13e7277 in _io_TextIOWrapper_close Modules/_io/clinic/textio.c.h:1160\n    #6 0x64c4d0f48571 in method_vectorcall_NOARGS Objects/descrobject.c:448\n    #7 0x64c4d0f28e7f in _PyObject_VectorcallTstate Include/internal/pycore_call.h:169\n    #8 0x64c4d0f28f72 in PyObject_Vectorcall Objects/call.c:327\n    #9 0x64c4d11a7056 in _PyEval_EvalFrameDefault Python/generated_cases.c.h:1620\n    #10 0x64c4d11eae54 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:121\n    #11 0x64c4d11eb148 in _PyEval_Vector Python/ceval.c:2001\n    #12 0x64c4d11eb3f8 in PyEval_EvalCode Python/ceval.c:884\n    #13 0x64c4d12e2507 in run_eval_code_obj Python/pythonrun.c:1365\n    #14 0x64c4d12e2723 in run_mod Python/pythonrun.c:1459\n    #15 0x64c4d12e357a in pyrun_file Python/pythonrun.c:1293\n    #16 0x64c4d12e6220 in _PyRun_SimpleFileObject Python/pythonrun.c:521\n    #17 0x64c4d12e64f6 in _PyRun_AnyFileObject Python/pythonrun.c:81\n    #18 0x64c4d133774d in pymain_run_file_obj Modules/main.c:410\n    #19 0x64c4d13379b4 in pymain_run_file Modules/main.c:429\n    #20 0x64c4d13391b2 in pymain_run_python Modules/main.c:691\n    #21 0x64c4d1339842 in Py_RunMain Modules/main.c:772\n    #22 0x64c4d1339a2e in pymain_main Modules/main.c:802\n    #23 0x64c4d1339db3 in Py_BytesMain Modules/main.c:826\n    #24 0x64c4d0dbd645 in main Programs/python.c:15\n    #25 0x7cb5cbe2a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58\n    #26 0x7cb5cbe2a28a in __libc_start_main_impl ../csu/libc-start.c:360\n    #27 0x64c4d0dbd574 in _start (/home/jackfromeast/Desktop/entropy/tasks/grammar-afl++-latest/targets/cpython/python+0x2dd574) (BuildId: ff3dc40ea460bd4beb2c3a72283cca525b319bf0)\n\nAddressSanitizer can not provide additional info.\nSUMMARY: AddressSanitizer: SEGV Include/object.h:277 in _Py_TYPE\n==1558952==ABORTING\n```\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-142706\n* gh-142755\n* gh-142757\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jackfromeast","@type":"Person","name":"jackfromeast"},"datePublished":"2025-12-11T18:57:03Z","url":"https://github.com/python/cpython/issues/142594"}

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:ae775db7-f10e-59dc-0b7f-ba06585e8121
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id94C6:34CAB:36DCC72:462AFC5:6B01F948
html-safe-noncec9835bbc51c7ceb1f026f53597b3b4dccc92d71ec7627504e7f3816c015f0781
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEM2OjM0Q0FCOjM2RENDNzI6NDYyQUZDNTo2QjAxRjk0OCIsInZpc2l0b3JfaWQiOiIzOTgyMTEwNDQ2NzUxNzA5NTEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1560360a59be7b39d8c31309483fa471384d8ffb61881672d6d5c5dd16033e2a
hovercard-subject-tagissue:3720595161
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/142594/issue_layout
twitter:imagehttps://opengraph.githubassets.com/aae3fe60448a0916663fb7cceec4b439d2e9a1c995be629d10ffe7a13eea29d0/python/cpython/issues/142594
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/aae3fe60448a0916663fb7cceec4b439d2e9a1c995be629d10ffe7a13eea29d0/python/cpython/issues/142594
og:image:altWhat happened? TextIOWrapper.close() queries the stream’s closed property. A user-defined RawIOBase.closed can re-enter and call wrapper.detach(), clearing self->buffer. The function then continues...
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-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/142594#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F142594
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%2F142594
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/142594
Reloadhttps://github.com/python/cpython/issues/142594
Reloadhttps://github.com/python/cpython/issues/142594
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/142594
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/142594
Null pointer dereference in TextIOWrapper.close() via re-entrant closed property that detaches bufferhttps://github.com/python/cpython/issues/142594#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 11, 2025https://github.com/python/cpython/issues/142594#issue-3720595161
gh-142594: fix by property calls io.TextIOWrapper.detach #142706https://github.com/python/cpython/pull/142706
[3.14] gh-142594: fix by property calls io.TextIOWrapper.detach (GH-142706) #142755https://github.com/python/cpython/pull/142755
[3.13] gh-142594: fix by property calls io.TextIOWrapper.detach (GH-142706) #142757https://github.com/python/cpython/pull/142757
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 11, 2025https://github.com/python/cpython/issues/142594#event-21511800631
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Dec 12, 2025https://github.com/python/cpython/issues/142594#issuecomment-3647453029
gh-140650https://github.com/python/cpython/issues/140650
https://github.com/yihong0618
yihong0618https://github.com/yihong0618
on Dec 13, 2025https://github.com/python/cpython/issues/142594#issuecomment-3648663702
encukouhttps://github.com/encukou
on Dec 15, 2025https://github.com/python/cpython/issues/142594#event-21567749673
gh-142594: fix by property calls io.TextIOWrapper.detach (GH-142706)https://github.com/python/cpython/commit/1d3854a19a376c1fc7f71e96c620f6bc2de8cd74
gh-142594https://github.com/python/cpython/issues/142594
GH-142706https://github.com/python/cpython/pull/142706
1d3854ahttps://github.com/python/cpython/commit/1d3854a19a376c1fc7f71e96c620f6bc2de8cd74
cmaloneyhttps://github.com/cmaloney
on Dec 15, 2025https://github.com/python/cpython/issues/142594#event-21571842266
[3.14] pythongh-142594: fix by property calls io.TextIOWrapper.detach (…https://github.com/cmaloney/cpython/commit/e055ec638c3ab5af15ed5ccbc2ce686740db1503
pythongh-142594https://github.com/python/cpython/issues/142594
…https://github.com/python/cpython/pull/142706
e055ec6https://github.com/cmaloney/cpython/commit/e055ec638c3ab5af15ed5ccbc2ce686740db1503
[3.13] pythongh-142594: fix by property calls io.TextIOWrapper.detach (…https://github.com/cmaloney/cpython/commit/148763ae059fb415922e512d8c3f01fd98ea62b6
pythongh-142594https://github.com/python/cpython/issues/142594
…https://github.com/python/cpython/pull/142706
148763ahttps://github.com/cmaloney/cpython/commit/148763ae059fb415922e512d8c3f01fd98ea62b6
fateleihttps://github.com/fatelei
on Dec 16, 2025https://github.com/python/cpython/issues/142594#event-21587639042
pythongh-142594: fix by property calls io.TextIOWrapper.detach (pytho…https://github.com/fatelei/cpython/commit/48bcca5a07c811ccbdaea17a944931f99a663fd5
pythongh-142594https://github.com/python/cpython/issues/142594
pytho…https://github.com/python/cpython/pull/142706
48bcca5https://github.com/fatelei/cpython/commit/48bcca5a07c811ccbdaea17a944931f99a663fd5
encukouhttps://github.com/encukou
on Dec 16, 2025https://github.com/python/cpython/issues/142594#event-21588413856
[3.14] gh-142594: fix by property calls io.TextIOWrapper.detach (GH-1…https://github.com/python/cpython/commit/58da2a9d94afc144da0e942fb293c4176da15174
gh-142594https://github.com/python/cpython/issues/142594
GH-1…https://github.com/python/cpython/pull/142706
58da2a9https://github.com/python/cpython/commit/58da2a9d94afc144da0e942fb293c4176da15174
[3.13] gh-142594: fix by property calls io.TextIOWrapper.detach (GH-1…https://github.com/python/cpython/commit/affd2f2ff24f45e672adf3638ab5e8dafc76c0e7
gh-142594https://github.com/python/cpython/issues/142594
GH-1…https://github.com/python/cpython/pull/142706
affd2f2https://github.com/python/cpython/commit/affd2f2ff24f45e672adf3638ab5e8dafc76c0e7
encukouhttps://github.com/encukou
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 16, 2025https://github.com/python/cpython/issues/142594#event-21588422623
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/142594
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/142594
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.