Skip to content

Commit

Permalink
pythongh-121860: Fix crash when materializing managed dict
Browse files Browse the repository at this point in the history
The object's inline values may be marked invalid if the materialized
dict was already initialized and then deleted.
  • Loading branch information
colesbury committed Jul 16, 2024
1 parent 69c68de commit 2a2e0a7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6683,11 +6683,18 @@ _PyObject_MaterializeManagedDict_LockHeld(PyObject *obj)
{
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(obj);

PyDictValues *values = _PyObject_InlineValues(obj);
PyInterpreterState *interp = _PyInterpreterState_GET();
PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
OBJECT_STAT_INC(dict_materialized_on_request);
PyDictObject *dict = make_dict_from_instance_attributes(interp, keys, values);

PyDictValues *values = _PyObject_InlineValues(obj);
PyDictObject *dict;
if (values->valid) {
PyInterpreterState *interp = _PyInterpreterState_GET();
PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
dict = make_dict_from_instance_attributes(interp, keys, values);
}
else {
dict = PyDict_New();
}
FT_ATOMIC_STORE_PTR_RELEASE(_PyObject_ManagedDictPointer(obj)->dict,
(PyDictObject *)dict);
return dict;
Expand Down

0 comments on commit 2a2e0a7

Please sign in to comment.