Close #14205: dict lookup raises a RuntimeError if the dict is modified during
a lookup.
"if you want to make a sandbox on top of CPython, you have to fix segfaults"
so let's fix segfaults!
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 83957ac..23ca442 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -347,12 +347,9 @@
return ep;
}
else {
- /* The compare did major nasty stuff to the
- * dict: start over.
- * XXX A clever adversary could prevent this
- * XXX from terminating.
- */
- return lookdict(mp, key, hash);
+ PyErr_SetString(PyExc_RuntimeError,
+ "dictionary changed size during lookup");
+ return NULL;
}
}
freeslot = NULL;
@@ -379,12 +376,9 @@
return ep;
}
else {
- /* The compare did major nasty stuff to the
- * dict: start over.
- * XXX A clever adversary could prevent this
- * XXX from terminating.
- */
- return lookdict(mp, key, hash);
+ PyErr_SetString(PyExc_RuntimeError,
+ "dictionary changed size during lookup");
+ return NULL;
}
}
else if (ep->me_key == dummy && freeslot == NULL)