gh-150587: Guard specialized list-int subscript indices#153004
Open
KRRT7 wants to merge 1 commit into
Open
Conversation
24dd20d to
f1a230b
Compare
Fidget-Spinner
approved these changes
Jul 4, 2026
Fidget-Spinner
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for catching this bug, just one request.
|
|
||
| assert(PyLong_CheckExact(sub)); | ||
| assert(PyList_CheckExact(list)); | ||
| DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub)); |
Member
There was a problem hiding this comment.
Why not use EXIT_IF here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-150587.
This supersedes the earlier closed PR gh-150588. That patch was moved into gh-150425 at the time, but the broad performance PR has not landed, so this keeps the correctness fix as a focused standalone change.
This makes the runtime invariant explicit for the specialized list/int subscript and store-subscript paths. Both opcodes are selected only after seeing a compact non-negative int index, but their runtime guard only ensures an exact int. If the same specialized code later sees a non-compact exact int, it must fall back before calling
_PyLong_CompactValue().Changes:
_PyLong_CompactValue()inBINARY_OP_SUBSCR_LIST_INTandSTORE_SUBSCR_LIST_INT._testinternalcapigenerated case headers.0, then calls it with2**30 + 2and verifies genericIndexErrorbehavior instead of using the low digit as the list index.Tests:
./python.exe -m test test_opcache -v./python.exe -m test test_opcache -m test_binary_subscr -m test_store_subscr -venv PYTHON_JIT=1 ./python.exe -m test test_opcache -m test_binary_subscr -m test_store_subscr -v