René's URL Explorer Experiment


Title: Null pointer dereference in `BufferedWriter.seek` during re-entrant close · Issue #143375 · python/cpython · GitHub

Open Graph Title: Null pointer dereference in `BufferedWriter.seek` during re-entrant close · Issue #143375 · python/cpython

X Title: Null pointer dereference in `BufferedWriter.seek` during re-entrant close · Issue #143375 · python/cpython

Description: What happened? BufferedWriter.seek asks the offset object for __index__ before it flushes pending bytes, so a crafted type can close the writer during that conversion, leaving the buffered write state freed while _bufferedwriter_raw_writ...

Open Graph Description: What happened? BufferedWriter.seek asks the offset object for __index__ before it flushes pending bytes, so a crafted type can close the writer during that conversion, leaving the buffered write st...

X Description: What happened? BufferedWriter.seek asks the offset object for __index__ before it flushes pending bytes, so a crafted type can close the writer during that conversion, leaving the buffered write st...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Null pointer dereference in `BufferedWriter.seek` during re-entrant close","articleBody":"### What happened?\n\n`BufferedWriter.seek` asks the offset object for `__index__` before it flushes pending bytes, so a crafted type can close the writer during that conversion, leaving the buffered write state freed while `_bufferedwriter_raw_write` retries the partial write and dereferences the stale pointer.\n\n**Proof of Concept:**\n\n```python\nimport io\n\nclass R:\n    def __init__(self):\n        self.calls = 0\n        self.closed = False\n    def writable(self): return True\n    def seekable(self): return True\n    def seek(self, off, whence=0): return 0\n    def write(self, mv):\n        self.calls += 1\n        if self.calls == 1: return len(mv) - 1\n        if self.calls == 2: raise BlockingIOError\n        mv.tobytes()\n        return len(mv)\n\nbw = io.BufferedWriter(R())\nbw.write(b\"ABCD\")\n\nclass T:\n    def __index__(self):\n        try: bw.close()\n        except Exception: pass\n        return 0\n\nbw.seek(T())\n```\n\n**Vulnerable Code Snippet:**\n\n\u003cdetails>\n\u003csummary>Click to expand\u003c/summary>\n\n```c\n/* Buggy Re-entrant Path */\nstatic PyObject *\n_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence)\n{\n    Py_off_t target;\n    /* ... */\n    target = PyNumber_AsOff_t(targetobj, PyExc_ValueError);  /* Reentrant call site */\n    if (target == -1 && PyErr_Occurred())\n        return NULL;\n    /* ... */\n    if (self->writable) {\n        res = _bufferedwriter_flush_unlocked(self);\n        /* ... */\n    }\n    /* ... */\n}\n\nstatic PyObject *\n_bufferedwriter_flush_unlocked(buffered *self)\n{\n    /* ... */\n    while (self->write_pos \u003c self->write_end) {\n        n = _bufferedwriter_raw_write(self,\n            self->buffer + self->write_pos,  /* crashing pointer derived */\n            Py_SAFE_DOWNCAST(self->write_end - self->write_pos,\n                             Py_off_t, Py_ssize_t));\n        /* ... */\n    }\n    /* ... */\n}\n\nstatic Py_ssize_t\n_bufferedwriter_raw_write(buffered *self, char *start, Py_ssize_t len)\n{\n    Py_buffer buf;\n    PyObject *memobj, *res;\n    /* NOTE: the buffer needn't be released as its object is NULL. */\n    if (PyBuffer_FillInfo(&buf, NULL, start, len, 1, PyBUF_CONTIG_RO) == -1)\n        return -1;\n    memobj = PyMemoryView_FromBuffer(&buf);\n    /* ... raw.write(memobj) ... */\n    return n;\n}\n\nint\nPyBuffer_ToContiguous(void *buf, const Py_buffer *src, Py_ssize_t len, char order)\n{\n    if (PyBuffer_IsContiguous(src, order)) {\n        memcpy((char *)buf, src->buf, len);  /* Crash site */\n        return 0;\n    }\n    /* ... */\n    return 0;\n}\n\n/* Clobbering Path */\nstatic PyObject *\n_io__Buffered_close_impl(buffered *self)\n{\n    /* ... */\n    if (self->buffer) {\n        PyMem_Free(self->buffer);  /* state mutate site */\n        self->buffer = NULL;\n    }\n    /* ... */\n    return res;\n}\n```\n\u003c/details>\n\n**Sanitizer Output:**\n\n\u003cdetails>\n\u003csummary>Click to expand\u003c/summary>\n\n```\nAddressSanitizer:DEADLYSIGNAL\n=================================================================\n==2188767==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000003 (pc 0x79e00cf88a84 bp 0x7ffd2d3db980 sp 0x7ffd2d3db928 T0)\n==2188767==The signal is caused by a READ memory access.\n==2188767==Hint: address points to the zero page.\n    #0 0x79e00cf88a84 in __memmove_avx_unaligned_erms ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:318\n    #1 0x654cee9496ed in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29\n    #2 0x654cee9496ed in PyBuffer_ToContiguous Objects/memoryobject.c:1063\n    #3 0x654cee949fd9 in memoryview_tobytes_impl Objects/memoryobject.c:2310\n    #4 0x654cee949fd9 in memoryview_tobytes Objects/clinic/memoryobject.c.h:335\n    #5 0x654cee83b3e7 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:169\n    #6 0x654cee83b3e7 in PyObject_Vectorcall Objects/call.c:327\n    #7 0x654cee6ef5a2 in _PyEval_EvalFrameDefault Python/generated_cases.c.h:1620\n    #8 0x654ceebba2a5 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:121\n    #9 0x654ceebba2a5 in _PyEval_Vector Python/ceval.c:2001\n    #10 0x654cee83d863 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:169\n    #11 0x654cee83d863 in PyObject_VectorcallMethod Objects/call.c:859\n    #12 0x654ceee3bfd5 in PyObject_CallMethodOneArg Include/cpython/abstract.h:74\n    #13 0x654ceee3bfd5 in _bufferedwriter_raw_write Modules/_io/bufferedio.c:1985\n    #14 0x654ceee3d3b6 in _bufferedwriter_flush_unlocked Modules/_io/bufferedio.c:2029\n    #15 0x654ceee4613e in _io__Buffered_seek_impl Modules/_io/bufferedio.c:1425\n    #16 0x654ceee4613e in _io__Buffered_seek Modules/_io/clinic/bufferedio.c.h:885\n    #17 0x654cee83b3e7 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:169\n    #18 0x654cee83b3e7 in PyObject_Vectorcall Objects/call.c:327\n    #19 0x654cee6ef5a2 in _PyEval_EvalFrameDefault Python/generated_cases.c.h:1620\n    #20 0x654ceebb9ad6 in _PyEval_EvalFrame Include/internal/pycore_ceval.h:121\n    #21 0x654ceebb9ad6 in _PyEval_Vector Python/ceval.c:2001\n    #22 0x654ceebb9ad6 in PyEval_EvalCode Python/ceval.c:884\n    #23 0x654ceecff16e in run_eval_code_obj Python/pythonrun.c:1365\n    #24 0x654ceecff16e in run_mod Python/pythonrun.c:1459\n    #25 0x654ceed03e17 in pyrun_file Python/pythonrun.c:1293\n    #26 0x654ceed03e17 in _PyRun_SimpleFileObject Python/pythonrun.c:521\n    #27 0x654ceed0493c in _PyRun_AnyFileObject Python/pythonrun.c:81\n    #28 0x654ceed77e3c in pymain_run_file_obj Modules/main.c:410\n    #29 0x654ceed77e3c in pymain_run_file Modules/main.c:429\n    #30 0x654ceed77e3c in pymain_run_python Modules/main.c:691\n    #31 0x654ceed7971e in Py_RunMain Modules/main.c:772\n    #32 0x654ceed7971e in pymain_main Modules/main.c:802\n    #33 0x654ceed7971e in Py_BytesMain Modules/main.c:826\n    #34 0x79e00ce2a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58\n    #35 0x79e00ce2a28a in __libc_start_main_impl ../csu/libc-start.c:360\n    #36 0x654cee713634 in _start (/home/jackfromeast/Desktop/entropy/targets/grammar-afl++-latest/targets/cpython/python+0x206634) (BuildId: 4d105290d0ad566a4d6f4f7b2f05fbc9e317b533)\n\nAddressSanitizer can not provide additional info.\nSUMMARY: AddressSanitizer: SEGV ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:318 in __memmove_avx_unaligned_erms\n==2188767==ABORTING\n```\n\u003c/details>\n\n### CPython versions tested on:\n\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, 19:29:54) [GCC 13.3.0]` | ASAN | 1 |\n\n\u003c/details>\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.15.0a1+ (heads/main:f5394c257ce, Oct 28 2025, 19:29:54) [GCC 13.3.0]\n\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-143577\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jackfromeast","@type":"Person","name":"jackfromeast"},"datePublished":"2026-01-03T04:05:54Z","url":"https://github.com/python/cpython/issues/143375"}

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:83ec1c2d-eee7-76d1-5cdf-b01ba6efdfac
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA43C:2679E9:30C7040:411CD0D:6B01EEF8
html-safe-nonce18d145e7ed200f65580ab77993ead4c17d6874b9e48b7b31da325c74dcd03d41
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDNDOjI2NzlFOTozMEM3MDQwOjQxMUNEMEQ6NkIwMUVFRjgiLCJ2aXNpdG9yX2lkIjoiMjI5Mjc3ODg4NzcwMzM4NTUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaccd9fa4ecfa3076c71b47f035449001fc6b2d20e97f2fe0a35aca9fb14812b305
hovercard-subject-tagissue:3777649483
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/143375/issue_layout
twitter:imagehttps://opengraph.githubassets.com/be4cf7e48379ed0a51e5517064fde2c2a02d5baddeae44bd2b6d2191e35792a3/python/cpython/issues/143375
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/be4cf7e48379ed0a51e5517064fde2c2a02d5baddeae44bd2b6d2191e35792a3/python/cpython/issues/143375
og:image:altWhat happened? BufferedWriter.seek asks the offset object for __index__ before it flushes pending bytes, so a crafted type can close the writer during that conversion, leaving the buffered write st...
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/143375#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F143375
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%2F143375
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/143375
Reloadhttps://github.com/python/cpython/issues/143375
Reloadhttps://github.com/python/cpython/issues/143375
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/143375
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/143375
Null pointer dereference in BufferedWriter.seek during re-entrant closehttps://github.com/python/cpython/issues/143375#top
https://github.com/tomasr8
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
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 Jan 3, 2026https://github.com/python/cpython/issues/143375#issue-3777649483
gh-143375: Fix a crash in BufferedWriter.seek when passing an object with a specially crafted __index__ #143577https://github.com/python/cpython/pull/143577
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 Jan 3, 2026https://github.com/python/cpython/issues/143375#event-21835326100
tomasr8https://github.com/tomasr8
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
on Jan 3, 2026https://github.com/python/cpython/issues/143375#event-21838345982
tomasr8https://github.com/tomasr8
on Jan 3, 2026https://github.com/python/cpython/issues/143375#event-21838347748
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/143375
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/143375
tomasr8https://github.com/tomasr8
3.13only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.13%22
3.14bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.14%22
3.15bugs and security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.15%22
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.