gh-154709: Fix out-of-bounds access in dict reverse iterator#154721
Open
BHUVANSH855 wants to merge 1 commit into
Open
gh-154709: Fix out-of-bounds access in dict reverse iterator#154721BHUVANSH855 wants to merge 1 commit into
BHUVANSH855 wants to merge 1 commit into
Conversation
BHUVANSH855
force-pushed
the
fix-154709-dict-reviter-bounds
branch
from
July 26, 2026 09:08
57fb030 to
f6d8284
Compare
brijkapadia
reviewed
Jul 26, 2026
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.
Summary
Fix an out-of-bounds access in
dictreviter_iter_lock_held()when a reverse dictionary iterator is used after the underlying dictionary is cleared and modified.The fix adds bounds checks before indexing into the dictionary's storage for both split-table and combined-table dictionaries. If the iterator's position is no longer valid, it now exits cleanly instead of accessing invalid memory.
A regression test has also been added to verify that this scenario no longer results in a crash.
Testing
./python -m test test_dict./python -m test test_gc./python -m test test_builtin./python -m test test_dict test_gc test_builtinreversed(dict)can read out of bounds and segfault (dictreviter_iter_lock_held) #154709