bpo-36452: dictiter: track maximum iteration count (GH-12596)

diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index e2603e1..7ea979c 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -3543,6 +3543,12 @@
             goto fail;
         key = entry_ptr->me_key;
     }
+    // We found an element (key), but did not expect it
+    if (di->len == 0) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "dictionary keys changed during iteration");
+        goto fail;
+    }
     di->di_pos = i+1;
     di->len--;
     Py_INCREF(key);