mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-36473: add maximum iteration check for dict .values() and .items() (GH-12619)
This commit is contained in:
parent
04694a306b
commit
b8311cf5e5
3 changed files with 36 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue