René's URL Explorer Experiment


Title: Several C API functions do not return NUL-terminated buffers · Issue #8685 · RustPython/RustPython · GitHub

Open Graph Title: Several C API functions do not return NUL-terminated buffers · Issue #8685 · RustPython/RustPython

X Title: Several C API functions do not return NUL-terminated buffers · Issue #8685 · RustPython/RustPython

Description: Summary The C API documents that the buffers returned by PyBytes_AsString(), PyByteArray_AsString(), and PyUnicode_AsUTF8AndSize() to contain an extra trailing NUL byte. RustPython instead returns pointers to the objects' exact-length Ru...

Open Graph Description: Summary The C API documents that the buffers returned by PyBytes_AsString(), PyByteArray_AsString(), and PyUnicode_AsUTF8AndSize() to contain an extra trailing NUL byte. RustPython instead returns ...

X Description: Summary The C API documents that the buffers returned by PyBytes_AsString(), PyByteArray_AsString(), and PyUnicode_AsUTF8AndSize() to contain an extra trailing NUL byte. RustPython instead returns ...

Opengraph URL: https://github.com/RustPython/RustPython/issues/8685

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Several C API functions do not return NUL-terminated buffers","articleBody":"## Summary\n\nThe C API documents that the buffers returned by `PyBytes_AsString()`, `PyByteArray_AsString()`, and `PyUnicode_AsUTF8AndSize()` to contain an extra trailing NUL byte. RustPython instead returns pointers to the objects' exact-length Rust buffers. Reading the documented byte at `data[len]` is therefore a heap-buffer-overflow.\n\nThe relevant implementations return raw pointers without adding a terminator: [`PyBytes_AsString()`](https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/bytesobject.rs#L41-L45), [`PyByteArray_AsString()`](https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/bytearrayobject.rs#L58-L62), and [`PyUnicode_AsUTF8AndSize()`](https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/unicodeobject.rs#L73-L92).\n\nThe bytearray case was [raised during review of PR #8009](https://github.com/RustPython/RustPython/pull/8009#discussion_r3340166727), but dismissed as intentional. However, I'm not sure whether this being a soundness issue was raised at that time.\n\n## Reproducer\n\nSave as `capi_trailing_null.c`:\n\n```c\n#include \u003cPython.h>\n#include \u003cstdio.h>\n\nint main(void)\n{\n    PyObject *bytes, *bytearray, *unicode;\n    char *bytes_data, *bytearray_data;\n    const char *unicode_data;\n    Py_ssize_t bytes_len, bytearray_len, unicode_len;\n    unsigned char bytes_trailing, bytearray_trailing, unicode_trailing;\n\n    Py_Initialize();\n\n    bytes = PyBytes_FromStringAndSize(\"abc\", 3);\n    bytearray = PyByteArray_FromStringAndSize(\"abc\", 3);\n    unicode = PyUnicode_FromStringAndSize(\"abc\", 3);\n    if (!bytes || !bytearray || !unicode)\n        return 2;\n\n    bytes_data = PyBytes_AsString(bytes);\n    bytearray_data = PyByteArray_AsString(bytearray);\n    unicode_data = PyUnicode_AsUTF8AndSize(unicode, &unicode_len);\n    bytes_len = PyBytes_Size(bytes);\n    bytearray_len = PyByteArray_Size(bytearray);\n    if (!bytes_data || !bytearray_data || !unicode_data ||\n        bytes_len \u003c 0 || bytearray_len \u003c 0)\n        return 2;\n\n    bytes_trailing = (unsigned char)bytes_data[bytes_len];\n    bytearray_trailing = (unsigned char)bytearray_data[bytearray_len];\n    unicode_trailing = (unsigned char)unicode_data[unicode_len];\n    printf(\"bytes: data[len] = 0x%02x\\n\", bytes_trailing);\n    printf(\"bytearray: data[len] = 0x%02x\\n\", bytearray_trailing);\n    printf(\"unicode UTF-8: data[len] = 0x%02x\\n\", unicode_trailing);\n\n    Py_Finalize();\n    return bytes_trailing || bytearray_trailing || unicode_trailing;\n}\n```\n\n\n## Expected\n\nWith CPython:\n\n```console\n$ cc -fsanitize=address -fno-omit-frame-pointer $(python3-config --cflags) capi_trailing_null.c $(python3-config --embed --ldflags) -o trailing-null-cpython\n$ ASAN_OPTIONS=detect_leaks=0 ./trailing-null-cpython\nbytes: data[len] = 0x00\nbytearray: data[len] = 0x00\nunicode UTF-8: data[len] = 0x00\n```\n\n## Actual\n\nFrom a RustPython checkout on macOS (use `.so` instead of `.dylib` on Linux):\n\n```console\n$ cargo build -p rustpython-capi\n$ cc -fsanitize=address -fno-omit-frame-pointer $(python3-config --includes) capi_trailing_null.c target/debug/librustpython_capi.dylib -o trailing-null-rustpython\n$ ASAN_OPTIONS=detect_leaks=0 ./trailing-null-rustpython\n==...==ERROR: AddressSanitizer: heap-buffer-overflow\n...\n0x... is located 0 bytes after 3-byte region [0x...,0x...)\n```\n\n## Python Documentation\n\nCPython documents the trailing byte for [`PyBytes_AsString()`](https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString), [`PyByteArray_AsString()`](https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString), and [`PyUnicode_AsUTF8AndSize()`](https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8AndSize).\n\n","author":{"url":"https://github.com/ngoldbaum","@type":"Person","name":"ngoldbaum"},"datePublished":"2026-09-10T15:22:01Z","url":"https://github.com/RustPython/RustPython/issues/8685"}

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:fb543c82-6930-5f8c-e4a1-abc1ca15cf2f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDD3A:A70A9:E8828D:133DADF:6B01D40E
html-safe-noncec9ba0fa352dfad1af00ceb1b2dd9398947001a5d86116ed146eef1e1c8dc5dd7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDNBOkE3MEE5OkU4ODI4RDoxMzNEQURGOjZCMDFENDBFIiwidmlzaXRvcl9pZCI6IjYyODc0MzA4OTU4ODQ0MjQyMDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac375f50383ada44b834bc9cc98aaadc0f6dd72cf91c4397ef2a8306d6e2a04239
hovercard-subject-tagissue:5414073907
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/RustPython/RustPython/8685/issue_layout
twitter:imagehttps://opengraph.githubassets.com/92acd434161022e6cb9611d9f4772423453ec7f73eb09acbcba050a8378bc8f6/RustPython/RustPython/issues/8685
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/92acd434161022e6cb9611d9f4772423453ec7f73eb09acbcba050a8378bc8f6/RustPython/RustPython/issues/8685
og:image:altSummary The C API documents that the buffers returned by PyBytes_AsString(), PyByteArray_AsString(), and PyUnicode_AsUTF8AndSize() to contain an extra trailing NUL byte. RustPython instead returns ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamengoldbaum
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/RustPython/RustPython/issues/8685#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fissues%2F8685
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%2FRustPython%2FRustPython%2Fissues%2F8685
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=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/issues/8685
Reloadhttps://github.com/RustPython/RustPython/issues/8685
Reloadhttps://github.com/RustPython/RustPython/issues/8685
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests132 (132)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
https://github.com/RustPython/RustPython
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8685
New issuehttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8685
Several C API functions do not return NUL-terminated buffershttps://github.com/RustPython/RustPython/issues/8685#top
C-bugSomething isn't workinghttps://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22C-bug%22
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 10, 2026https://github.com/RustPython/RustPython/issues/8685#issue-5414073907
PyBytes_AsString()https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/bytesobject.rs#L41-L45
PyByteArray_AsString()https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/bytearrayobject.rs#L58-L62
PyUnicode_AsUTF8AndSize()https://github.com/RustPython/RustPython/blob/8195385d6176a6ef94c4653f8093aeca6c7ca6c5/crates/capi/src/unicodeobject.rs#L73-L92
raised during review of PR #8009https://github.com/RustPython/RustPython/pull/8009#discussion_r3340166727
PyBytes_AsString()https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
PyByteArray_AsString()https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString
PyUnicode_AsUTF8AndSize()https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8AndSize
ngoldbaumhttps://github.com/ngoldbaum
C-bugSomething isn't workinghttps://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22C-bug%22
on Sep 10, 2026https://github.com/RustPython/RustPython/issues/8685#event-30912644735
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 10, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5621180651
python/cpython#157236https://github.com/python/cpython/pull/157236
https://github.com/bschoenmaeckers
bschoenmaeckershttps://github.com/bschoenmaeckers
on Sep 13, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5653588749
@ngoldbaumhttps://github.com/ngoldbaum
https://github.com/bschoenmaeckers
bschoenmaeckershttps://github.com/bschoenmaeckers
on Sep 15, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5678002987
python/cpython#157236https://github.com/python/cpython/pull/157236
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 15, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5679610164
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 15, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5679762367
python/cpython#157236https://github.com/python/cpython/pull/157236
PyBytes_AsString()https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString
PyByteArray_AsString()https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString
https://github.com/bschoenmaeckers
bschoenmaeckershttps://github.com/bschoenmaeckers
on Sep 15, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5679789949
https://github.com/youknowone
youknowonehttps://github.com/youknowone
on Sep 16, 2026https://github.com/RustPython/RustPython/issues/8685#issuecomment-5691466496
Sign up for freehttps://github.com/signup?return_to=https://github.com/RustPython/RustPython/issues/8685
Sign in to commenthttps://github.com/login?return_to=https://github.com/RustPython/RustPython/issues/8685
C-bugSomething isn't workinghttps://github.com/RustPython/RustPython/issues?q=state%3Aopen%20label%3A%22C-bug%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.