René's URL Explorer Experiment


Title: Double-inheriting from two buffer classes can cause corruption · Issue #104297 · python/cpython · GitHub

Open Graph Title: Double-inheriting from two buffer classes can cause corruption · Issue #104297 · python/cpython

X Title: Double-inheriting from two buffer classes can cause corruption · Issue #104297 · python/cpython

Description: If you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements bf_getbuffer and the second also implements bf_releasebuffer, then if you create a memoryview from the child class, on ...

Open Graph Description: If you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements bf_getbuffer and the second also implements bf_releasebuffer, then if you creat...

X Description: If you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements bf_getbuffer and the second also implements bf_releasebuffer, then if you creat...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Double-inheriting from two buffer classes can cause corruption","articleBody":"If you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements `bf_getbuffer` and the second also implements `bf_releasebuffer`, then if you create a memoryview from the child class, on release the second class's `bf_releasebuffer` will be called, which may break that class's invariants.\r\n\r\nDemonstration:\r\n\r\n\u003cdetails\u003e\r\n\r\n```\r\ndiff --git a/Modules/_testcapi/buffer.c b/Modules/_testcapi/buffer.c\r\nindex aff9a477ef..3cfa19a57b 100644\r\n--- a/Modules/_testcapi/buffer.c\r\n+++ b/Modules/_testcapi/buffer.c\r\n@@ -89,14 +89,50 @@ static PyTypeObject testBufType = {\r\n     .tp_members = testbuf_members\r\n };\r\n \r\n+\r\n+static int\r\n+getbufferonly_getbuf(testBufObject *self, Py_buffer *view, int flags)\r\n+{\r\n+    PyObject *bytes = PyBytes_FromString(\"test\");\r\n+    if (bytes == NULL) {\r\n+        return -1;\r\n+    }\r\n+    // Save a reference\r\n+    if (PyObject_SetAttrString((PyObject *)Py_TYPE(self), \"bytes\", bytes) \u003c 0) {\r\n+        return -1;\r\n+    }\r\n+    int buf = PyObject_GetBuffer(bytes, view, flags);\r\n+    view-\u003eobj = Py_NewRef(self);\r\n+    return buf;\r\n+}\r\n+\r\n+static PyBufferProcs getbufferonly_as_buffer = {\r\n+    .bf_getbuffer = (getbufferproc) getbufferonly_getbuf,\r\n+};\r\n+\r\n+static PyTypeObject getBufferOnlyType = {\r\n+    PyVarObject_HEAD_INIT(NULL, 0)\r\n+    .tp_name = \"getBufferOnlyType\",\r\n+    .tp_basicsize = sizeof(PyObject),\r\n+    .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,\r\n+    .tp_new = PyType_GenericNew,\r\n+    .tp_as_buffer = \u0026getbufferonly_as_buffer,\r\n+};\r\n+\r\n int\r\n _PyTestCapi_Init_Buffer(PyObject *m) {\r\n     if (PyType_Ready(\u0026testBufType) \u003c 0) {\r\n         return -1;\r\n     }\r\n+    if (PyType_Ready(\u0026getBufferOnlyType) \u003c 0) {\r\n+        return -1;\r\n+    }\r\n     if (PyModule_AddObjectRef(m, \"testBuf\", (PyObject *)\u0026testBufType)) {\r\n         return -1;\r\n     }\r\n+    if (PyModule_AddObjectRef(m, \"getBufferOnly\", (PyObject *)\u0026getBufferOnlyType)) {\r\n+        return -1;\r\n+    }\r\n \r\n     return 0;\r\n }\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\n```\r\n% ./python.exe \r\nPython 3.12.0a7+ (heads/pep688fix-dirty:5536853ed0, May  7 2023, 07:53:16) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n\u003e\u003e\u003e import _testcapi\r\n\u003e\u003e\u003e class X(_testcapi.getBufferOnly, bytearray): pass\r\n... \r\n\u003e\u003e\u003e with memoryview(X()): pass\r\n... \r\nAssertion failed: (obj-\u003eob_exports \u003e= 0), function bytearray_releasebuffer, file bytearrayobject.c, line 64.\r\nzsh: abort      ./python.exe\r\n```\r\n\r\nThis is unlikely to happen in practice because in practice any useful C buffer class will have to store some data in its C struct, so it won't be possible to double-inherit from it and another buffer, but still we should ideally protect against it.\r\n\r\nI found out about this case while playing with PEP-688 edge cases in #104227, but the reproduction case does not rely on PEP 688 changes, and it should reproduce also on earlier Python versions. (The exact assertion failure won't, because I added that assertion in #104227; previously, you'd just set the bytearray's ob_exports field to -1 and havoc would ensue.)","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2023-05-08T17:01:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/104297/cpython/issues/104297"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:480c97f1-5bb9-acbb-0c08-2993ab63b45b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD2FA:2650A8:2BD484:3A0D27:6969C1D5
html-safe-nonceacbe84d2358ebb9d75a442df780abb317bc572a8194dc704a36daabf784c52a6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkZBOjI2NTBBODoyQkQ0ODQ6M0EwRDI3OjY5NjlDMUQ1IiwidmlzaXRvcl9pZCI6IjczMTE0MDYzNzU0NTMxODAzNzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac4aa975ec7dedfc828ca603c6467d6f706249494044c14a3e5895d115a52898fb
hovercard-subject-tagissue:1700603079
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/104297/issue_layout
twitter:imagehttps://opengraph.githubassets.com/101008f8e7f21bf6d60d1674a59e97623aa0619bcb4ddcbb0c94361e6f84209f/python/cpython/issues/104297
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/101008f8e7f21bf6d60d1674a59e97623aa0619bcb4ddcbb0c94361e6f84209f/python/cpython/issues/104297
og:image:altIf you have a class that double-inherits from two buffer classes implemented in C, of which the first only implements bf_getbuffer and the second also implements bf_releasebuffer, then if you creat...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJelleZijlstra
hostnamegithub.com
expected-hostnamegithub.com
Noneacedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056
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
release83c08c21cdda978090dc44364b71aa5bc6dcea79
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/104297#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F104297
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F104297
Sign up https://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/104297
Reloadhttps://github.com/python/cpython/issues/104297
Reloadhttps://github.com/python/cpython/issues/104297
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/104297
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/104297
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/104297
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/104297
Double-inheriting from two buffer classes can cause corruptionhttps://github.com/python/cpython/issues/104297#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/JelleZijlstra
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on May 8, 2023https://github.com/python/cpython/issues/104297#issue-1700603079
PEP-688https://peps.python.org/688
#104227https://github.com/python/cpython/pull/104227
#104227https://github.com/python/cpython/pull/104227
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-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.