Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-132461: Fix crash in OrderedDict.setdefault when key has unstable hash #132462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix crash in OrderedDict.setdefault when key has unstable hash
Replaced assertion with a runtime check in OrderedDict_setdefault_impl
to gracefully handle keys with changing hash values. If such a key is
detected, a TypeError is raised instead of aborting the interpreter.
  • Loading branch information
dura0ok committed Apr 13, 2025
commit 08759edf14a9678bbd2728e550dd7cd3de212e1c
6 changes: 5 additions & 1 deletion 6 Objects/odictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,11 @@ OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
if (result == NULL) {
if (PyErr_Occurred())
return NULL;
assert(_odict_find_node(self, key) == NULL);
if (_odict_find_node(self, key) != NULL) {
PyErr_SetString(PyExc_RuntimeError,
"OrderedDict key appears to change its hash value over time");
return NULL;
}
if (PyODict_SetItem((PyObject *)self, key, default_value) >= 0) {
result = Py_NewRef(default_value);
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.