bpo-36473: add maximum iteration check for dict .values() and .items() (GH-12619)

This commit is contained in:
Thomas Perl 2019-04-02 11:30:10 +02:00 committed by Inada Naoki
parent 04694a306b
commit b8311cf5e5
3 changed files with 36 additions and 2 deletions

View file

@ -3630,6 +3630,12 @@ dictiter_iternextvalue(dictiterobject *di)
goto fail;
value = entry_ptr->me_value;
}
// We found an element, 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(value);
@ -3713,6 +3719,12 @@ dictiter_iternextitem(dictiterobject *di)
key = entry_ptr->me_key;
value = entry_ptr->me_value;
}
// We found an element, 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);