Title: Specialized list subscript/store can mishandle non-compact int indices · Issue #153002 · python/cpython · GitHub
Open Graph Title: Specialized list subscript/store can mishandle non-compact int indices · Issue #153002 · python/cpython
X Title: Specialized list subscript/store can mishandle non-compact int indices · Issue #153002 · python/cpython
Description: Bug description: The specialized list/int subscript and store paths can be entered after a code object was specialized with a compact non-negative int index, then later called with a non-compact exact int index. At specialization time, B...
Open Graph Description: Bug description: The specialized list/int subscript and store paths can be entered after a code object was specialized with a compact non-negative int index, then later called with a non-compact ex...
X Description: Bug description: The specialized list/int subscript and store paths can be entered after a code object was specialized with a compact non-negative int index, then later called with a non-compact ex...
Opengraph URL: https://github.com/python/cpython/issues/153002
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Specialized list subscript/store can mishandle non-compact int indices","articleBody":"### Bug description:\n\nThe specialized list/int subscript and store paths can be entered after a code object was specialized with a compact non-negative int index, then later called with a non-compact exact int index.\n\nAt specialization time, `BINARY_OP_SUBSCR_LIST_INT` and `STORE_SUBSCR_LIST_INT` require `_PyLong_IsNonNegativeCompact(sub)`, but the runtime macro only guards with `_GUARD_TOS_INT`. The specialized operation then calls `_PyLong_CompactValue()` without rechecking compactness.\n\nOn debug builds this can trip the `_PyLong_CompactValue()` assertion. On release builds, a non-compact value whose low digit is zero, such as `1 \u003c\u003c 64`, can be treated as index `0` rather than falling back to generic list indexing and raising `IndexError`.\n\nMinimal CPython-internal reproducer:\n\n```python\nimport dis\nimport _testinternalcapi\n\ndef get(index):\n a = [1, 2, 3]\n return a[index]\n\nfor _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):\n assert get(0) == 1\n\nassert \"BINARY_OP_SUBSCR_LIST_INT\" in {\n instruction.opname for instruction in dis.get_instructions(get, adaptive=True)\n}\nget(1 \u003c\u003c 64)\n```\n\nThe same invariant issue applies to `STORE_SUBSCR_LIST_INT` after warming with index `0` and then storing with `1 \u003c\u003c 64`.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-153004\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/KRRT7","@type":"Person","name":"KRRT7"},"datePublished":"2026-07-04T07:22:45Z","url":"https://github.com/python/cpython/issues/153002"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:7f0b7010-485c-020c-4737-1f0ae8f78906 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AD60:387E7D:37F77C:4C7809:6AECC9E6 |
| html-safe-nonce | e063cc92622252b22634b9c0bebfc892aa88fb52997f51839f9e8495aaf105ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRDYwOjM4N0U3RDozN0Y3N0M6NEM3ODA5OjZBRUNDOUU2IiwidmlzaXRvcl9pZCI6IjI0MTgwNzg3OTI5NDY3MzY2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bfe4f1377bf61aef7b90accad5954d34916462fbfca7f2f991fefeff7bdce245 |
| hovercard-subject-tag | issue:4808089018 |
| 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/153002/issue_layout |
| twitter:image | https://opengraph.githubassets.com/765fbf5a514f568aa6a51e12b7c2790f47ff5ee414af5eec1c1364c039d82a89/python/cpython/issues/153002 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/765fbf5a514f568aa6a51e12b7c2790f47ff5ee414af5eec1c1364c039d82a89/python/cpython/issues/153002 |
| og:image:alt | Bug description: The specialized list/int subscript and store paths can be entered after a code object was specialized with a compact non-negative int index, then later called with a non-compact ex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KRRT7 |
| hostname | github.com |
| expected-hostname | github.com |
| None | dc0b519c5798dc1150b88dc4c06a8b9634d0069218dc04e469970e76aad74016 |
| 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 | db139f0bf57b59bf9a8c4abb0849924d6c6ca559 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width