René's URL Explorer Experiment


Title: ctypes: out-of-bounds read/write in bool() and argument passing after resize() · Issue #160708 · python/cpython · GitHub

Open Graph Title: ctypes: out-of-bounds read/write in bool() and argument passing after resize() · Issue #160708 · python/cpython

X Title: ctypes: out-of-bounds read/write in bool() and argument passing after resize() · Issue #160708 · python/cpython

Description: Crash report After ctypes.resize(), the buffer of a simple ctypes object is larger than the type itself. Two places in _ctypes.c use the buffer size (b_size) instead of the type size and go out of bounds. Found with a fuzzer. Tested on m...

Open Graph Description: Crash report After ctypes.resize(), the buffer of a simple ctypes object is larger than the type itself. Two places in _ctypes.c use the buffer size (b_size) instead of the type size and go out of ...

X Description: Crash report After ctypes.resize(), the buffer of a simple ctypes object is larger than the type itself. Two places in _ctypes.c use the buffer size (b_size) instead of the type size and go out of ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ctypes: out-of-bounds read/write in bool() and argument passing after resize()","articleBody":"### Crash report\n\nAfter `ctypes.resize()`, the buffer of a simple ctypes object is larger than the type itself. Two places in `_ctypes.c` use the buffer size (`b_size`) instead of the type size and go out of bounds.\n\nFound with a fuzzer. Tested on main (c436e8d8359).\n\n**1. Reading out of bounds in `bool()`**\n\n```python\nimport ctypes\nx = ctypes.c_bool()\nctypes.resize(x, 190)\nbool(x)\n```\n\n```\n==94599==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7f54a2fc1b71 at pc 0x563480cae666 bp 0x7ffc5c95adf0 sp 0x7ffc5c95a598\nREAD of size 190 at 0x7f54a2fc1b71 thread T0\n    #0 in MemcmpInterceptorCommon(void*, int (*)(void const*, void const*, unsigned long), void const*, void const*, unsigned long) /usr/src/RPM/BUILD/llvm-project-18/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:814:7\n    #1 in memcmp /usr/src/RPM/BUILD/llvm-project-18/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:845:10\n    #2 in PyObject_IsTrue Objects/object.c:2163:15\n    #3 in bool_vectorcall Objects/boolobject.c:60:14\n    #4 in _PyObject_VectorcallTstate Include/internal/pycore_call.h:143:11\n    ...\n\n0x7f54a2fc1b71 is located 0 bytes after global variable '.str.245' defined in '/host/triage/cpython/Modules/_ctypes/_ctypes.c:5525' (0x7f54a2fc1b60) of size 17\nSUMMARY: AddressSanitizer: global-buffer-overflow Objects/object.c:2163:15 in PyObject_IsTrue\n```\n\n`Simple_bool_impl` compares the object with a 16-byte string literal (`_ctypes.c:5525`) using `b_size` as the length.\n\nWithout ASAN, a debug build aborts with:\n```\nFatal Python error: _Py_CheckFunctionResult: a function returned NULL without setting an exception\nPython runtime state: initialized\nSystemError: \u003cclass 'bool'> returned NULL without setting an exception\n```\n\n**2. Writing out of bounds when calling a function**\n\n```python\nimport ctypes\nx = ctypes.c_bool()\nctypes.resize(x, 128)\nabs_ = ctypes.CDLL(None).abs\nabs_.argtypes = (ctypes.c_bool,)\nabs_(x)\n```\n\n```\n==94604==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x508000021000 at pc 0x55a5906863d4 bp 0x7fff29dbc9b0 sp 0x7fff29dbc170\nWRITE of size 128 at 0x508000021000 thread T0\n    #0 in __asan_memcpy /usr/src/RPM/BUILD/llvm-project-18/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:63:3\n    #1 in PyCSimpleType_paramfunc Modules/_ctypes/_ctypes.c:2320:5\n    #2 in ConvParam Modules/_ctypes/callproc.c:728:16\n    #3 in _ctypes_callproc Modules/_ctypes/callproc.c:1308:19\n    #4 in PyCFuncPtr_call Modules/_ctypes/_ctypes.c:4698:14\n    ...\n\n0x508000021000 is located 0 bytes after 96-byte region [0x508000020fa0,0x508000021000)\nallocated by thread T0 here:\n    #0 in malloc /usr/src/RPM/BUILD/llvm-project-18/compiler-rt/lib/asan/asan_malloc_linux.cpp:68:3\n    #1 in _PyObject_MallocWithType Include/internal/pycore_object_alloc.h:46:17\n    #2 in gc_alloc Python/gc.c:2034:17\n    #3 in _PyObject_GC_New Python/gc.c:2054:20\n    #4 in PyCArgObject_new Modules/_ctypes/callproc.c:520:9\n\nSUMMARY: AddressSanitizer: heap-buffer-overflow Modules/_ctypes/_ctypes.c:2320:5 in PyCSimpleType_paramfunc\n```\n\n`PyCSimpleType_paramfunc` copies `b_size` bytes into the `value` union of `PyCArgObject`. The union is 32 bytes on x86-64 (its largest member is `long double G[2]`), so the copy goes past the end of the object.\n\nWithout ASAN, a debug build aborts with:\n```\nFatal Python error: _PyMem_DebugRawFree: bad trailing pad byte\nPython runtime state: initialized\n```\n\nI think both places should use `info->size`, as gh-159767 did in `_ctypes_Simple_value_get_impl`. I'm going to open a PR.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.16.0a1+dev (heads/main:c436e8d8359, Oct 26 2026, 12:26:29) [Clang 18.1.8 ]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160720\n* gh-161806\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/DmitryTD","@type":"Person","name":"DmitryTD"},"datePublished":"2026-10-26T13:59:51Z","url":"https://github.com/python/cpython/issues/160708"}

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:78d91dbd-9f45-8445-be25-6b68dec359c3
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD212:16AB79:436EBD1:55958C4:6B022F41
html-safe-nonce160fb6b909f0422e33aa5e40bd9a79144c6c75631ee01b61c73a22f422fa76f3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjEyOjE2QUI3OTo0MzZFQkQxOjU1OTU4QzQ6NkIwMjJGNDEiLCJ2aXNpdG9yX2lkIjoiMzU1OTg0MDMwNDU2OTkyMTM0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb1c2a74d1455aa4b5bb18ec4b6027bd879ec4bb6422dc0f8e8cf624836f269ec
hovercard-subject-tagissue:6041166287
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/160708/issue_layout
twitter:imagehttps://opengraph.githubassets.com/92e9b971da384798ddf19e6ff542564ad0bb2efb380ba69c8984c914ba130390/python/cpython/issues/160708
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/92e9b971da384798ddf19e6ff542564ad0bb2efb380ba69c8984c914ba130390/python/cpython/issues/160708
og:image:altCrash report After ctypes.resize(), the buffer of a simple ctypes object is larger than the type itself. Two places in _ctypes.c use the buffer size (b_size) instead of the type size and go out of ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDmitryTD
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/160708#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F160708
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%2F160708
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/160708
Reloadhttps://github.com/python/cpython/issues/160708
Reloadhttps://github.com/python/cpython/issues/160708
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/160708
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/160708
ctypes: out-of-bounds read/write in bool() and argument passing after resize()https://github.com/python/cpython/issues/160708#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-ctypeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-ctypes%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/DmitryTD
DmitryTDhttps://github.com/DmitryTD
on Oct 26, 2026https://github.com/python/cpython/issues/160708#issue-6041166287
c436e8dhttps://github.com/python/cpython/commit/c436e8d83597c6f8c1bc7e37812c98d46670c29a
gh-159767https://github.com/python/cpython/pull/159767
gh-160708: Use the type size for resized ctypes simple objects #160720https://github.com/python/cpython/pull/160720
[3.15] gh-160708: Use the type size for resized ctypes simple objects (GH-160720) #161806https://github.com/python/cpython/pull/161806
DmitryTDhttps://github.com/DmitryTD
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 Oct 26, 2026https://github.com/python/cpython/issues/160708#event-34265979620
NekoAsakurahttps://github.com/NekoAsakura
topic-ctypeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-ctypes%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Oct 26, 2026https://github.com/python/cpython/issues/160708#event-34291837492
ZeroIntensityhttps://github.com/ZeroIntensity
on Nov 4, 2026https://github.com/python/cpython/issues/160708#event-35137397416
gh-160708: Use the type size for resized ctypes simple objects (GH-16…https://github.com/python/cpython/commit/44579b0da558b5a45b17358dffbc4a2ee947cdf7
gh-160708https://github.com/python/cpython/issues/160708
GH-16…https://github.com/python/cpython/pull/160720
44579b0https://github.com/python/cpython/commit/44579b0da558b5a45b17358dffbc4a2ee947cdf7
hugovkhttps://github.com/hugovk
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Nov 9, 2026https://github.com/python/cpython/issues/160708#event-35553627520
ZeroIntensityhttps://github.com/ZeroIntensity
on Nov 11, 2026https://github.com/python/cpython/issues/160708#event-35821323350
[3.15] gh-160708: Use the type size for resized ctypes simple objects (…https://github.com/python/cpython/commit/f539f3475fbdc9fff93b29f7dec01eff499e7694
gh-160708https://github.com/python/cpython/issues/160708
…https://github.com/python/cpython/pull/160720
f539f34https://github.com/python/cpython/commit/f539f3475fbdc9fff93b29f7dec01eff499e7694
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/160708
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/160708
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-ctypeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-ctypes%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.