Title: Disallow arbitrary types in co_consts · Issue #122850 · python/cpython · GitHub
Open Graph Title: Disallow arbitrary types in co_consts · Issue #122850 · python/cpython
X Title: Disallow arbitrary types in co_consts · Issue #122850 · python/cpython
Description: co_consts can contain values of any type, including mutable ones. For example: def f(): print(()) code = f.__code__ code = code.replace(co_consts=(None, [])) exec(code) This is dangerous especially in the free-threaded build, which de-du...
Open Graph Description: co_consts can contain values of any type, including mutable ones. For example: def f(): print(()) code = f.__code__ code = code.replace(co_consts=(None, [])) exec(code) This is dangerous especially...
X Description: co_consts can contain values of any type, including mutable ones. For example: def f(): print(()) code = f.__code__ code = code.replace(co_consts=(None, [])) exec(code) This is dangerous especially...
Opengraph URL: https://github.com/python/cpython/issues/122850
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Disallow arbitrary types in co_consts","articleBody":"`co_consts` can contain values of any type, including mutable ones. For example:\r\n\r\n```py\r\ndef f():\r\n print(())\r\n\r\ncode = f.__code__\r\ncode = code.replace(co_consts=(None, []))\r\nexec(code)\r\n```\r\n\r\nThis is dangerous especially in the free-threaded build, which\r\n- de-duplicates constants and\r\n- immortalizes constants and relies them to be immortal\r\n\r\nThe “feature” is untested, as seen from the above snippet failing an assertion in free-threaded build.\r\n\r\nMutable subclasses of immutable built-in types are especially “interesting” here.\r\n\r\nA solution would be to only allow *built-in immutable marshallable* types (booleans, integers, floating-point numbers, complex numbers, strings, bytes, tuples, frozensets, code objects, `None`, `Ellipsis`, `StopIteration`), excluding sublasses. That's a backwards-incompatible change.\r\n\r\nNote that CPython now already recursively analyzes `co_consts`; there's little cost to doing additional inspection.\r\n\r\nMy current plan is:\r\n- Disallow “bad” values in free-threaded builds in 3.14, as this build is still experimental and this breaks vital invariants.\r\n- Deprecate “bad” values in regular build, and initially plan to disallow them in 3.16. (Minimal PEP-387 deprecation period chosen because this “feature” is very likely to interfere with optimizations, and unlikely to get proper test coverage.)\r\n\r\nUntil then, please avoid assuming that code constants are “sane”. (cc @brandtbucher @markshannon @colesbury)","author":{"url":"https://github.com/encukou","@type":"Person","name":"encukou"},"datePublished":"2024-08-09T08:54:35Z","url":"https://github.com/python/cpython/issues/122850"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0dc7be06-54e2-8a84-571a-b5d056268095 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C880:36A3E:37DC17F:4A76021:6B021B73 |
| html-safe-nonce | 90a190631f8c4aa0b819fea6c354001fc29723d177f603abe20feb754433f7b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODgwOjM2QTNFOjM3REMxN0Y6NEE3NjAyMTo2QjAyMUI3MyIsInZpc2l0b3JfaWQiOiI1OTE0NTE5NzM3NjM4OTg0NTYzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | df19b51142b0a43c3463e76a1bced6af2dbe8ae36593ceb8d69b6bfa87db75b9 |
| hovercard-subject-tag | issue:2457446717 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/122850/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e98f9ebcd10ae1ea3afd20ab51b224f961d7b40311671311dbbaaa3b4fb8c03a/python/cpython/issues/122850 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e98f9ebcd10ae1ea3afd20ab51b224f961d7b40311671311dbbaaa3b4fb8c03a/python/cpython/issues/122850 |
| og:image:alt | co_consts can contain values of any type, including mutable ones. For example: def f(): print(()) code = f.__code__ code = code.replace(co_consts=(None, [])) exec(code) This is dangerous especially... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | encukou |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width