Skip to content

gh-154709: Fix out-of-bounds access in dict reverse iterator - #154721

Merged
serhiy-storchaka merged 5 commits into
python:mainfrom
BHUVANSH855:fix-154709-dict-reviter-bounds
Jul 29, 2026
Merged

gh-154709: Fix out-of-bounds access in dict reverse iterator#154721
serhiy-storchaka merged 5 commits into
python:mainfrom
BHUVANSH855:fix-154709-dict-reviter-bounds

Conversation

@BHUVANSH855

@BHUVANSH855 BHUVANSH855 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

  • Reproduced the original crash using the provided reproducer before the fix.
  • Verified that the reproducer no longer crashes after the fix.
  • Ran:
    • ./python -m test test_dict
    • ./python -m test test_gc
    • ./python -m test test_builtin
    • ./python -m test test_dict test_gc test_builtin

@BHUVANSH855
BHUVANSH855 force-pushed the fix-154709-dict-reviter-bounds branch from 57fb030 to f6d8284 Compare July 26, 2026 09:08
Comment thread Objects/dictobject.c Outdated
Comment thread Lib/test/test_dict.py Outdated
Comment thread Objects/dictobject.c Outdated
Comment thread Objects/dictobject.c Outdated
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 29, 2026
Comment thread Objects/dictobject.c Outdated
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka merged commit 3fd36fa into python:main Jul 29, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @BHUVANSH855 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 29, 2026

Copy link
Copy Markdown

GH-154888 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 29, 2026
@bedevere-app

bedevere-app Bot commented Jul 29, 2026

Copy link
Copy Markdown

GH-154889 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 29, 2026
@bedevere-app

bedevere-app Bot commented Jul 29, 2026

Copy link
Copy Markdown

GH-154890 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 29, 2026
serhiy-storchaka pushed a commit that referenced this pull request Jul 29, 2026
…H-154721) (GH-154890)

(cherry picked from commit 3fd36fa)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 29, 2026
…H-154721) (GH-154889)

(cherry picked from commit 3fd36fa)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 29, 2026
…H-154721) (GH-154888)

(cherry picked from commit 3fd36fa)

Co-authored-by: Bhuvansh <bhuvanshkataria@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants