aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-07-16 21:26:01 +0200
committerGitHub <noreply@github.com>2024-07-16 19:26:01 +0000
commit66130290846ec9438d80d99a4d1f7754e73c3078 (patch)
tree4ce21f9400dbca6353028a670d8508d023e48022 /Objects
parent[3.13] gh-121130: Fix f-string format specifiers with debug expressions (GH-1... (diff)
downloadcpython-66130290846ec9438d80d99a4d1f7754e73c3078.tar.gz
cpython-66130290846ec9438d80d99a4d1f7754e73c3078.tar.bz2
cpython-66130290846ec9438d80d99a4d1f7754e73c3078.zip
[3.13] gh-121860: Fix crash when materializing managed dict (GH-121866) (#121867)
The object's inline values may be marked invalid if the materialized dict was already initialized and then deleted. (cherry picked from commit 162b41f57757c1df40eb377985e2e877fb0f0ea3) Co-authored-by: Sam Gross <colesbury@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 48aed1e4da8..6b26baaf3b5 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -6683,13 +6683,20 @@ _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 = (PyDictObject *)PyDict_New();
+ }
FT_ATOMIC_STORE_PTR_RELEASE(_PyObject_ManagedDictPointer(obj)->dict,
- (PyDictObject *)dict);
+ dict);
return dict;
}