mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-101765: Fix SystemError / segmentation fault in iter __reduce__
when internal access of builtins.__dict__
exhausts the iterator (#101769)
This commit is contained in:
parent
89b4c12053
commit
54dfa14c5a
9 changed files with 148 additions and 23 deletions
|
@ -3444,18 +3444,22 @@ listiter_reduce_general(void *_it, int forward)
|
|||
{
|
||||
PyObject *list;
|
||||
|
||||
/* _PyEval_GetBuiltin can invoke arbitrary code,
|
||||
* call must be before access of iterator pointers.
|
||||
* see issue #101765 */
|
||||
|
||||
/* the objects are not the same, index is of different types! */
|
||||
if (forward) {
|
||||
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
|
||||
_PyListIterObject *it = (_PyListIterObject *)_it;
|
||||
if (it->it_seq) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index);
|
||||
}
|
||||
} else {
|
||||
PyObject *reversed = _PyEval_GetBuiltin(&_Py_ID(reversed));
|
||||
listreviterobject *it = (listreviterobject *)_it;
|
||||
if (it->it_seq) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(reversed)),
|
||||
it->it_seq, it->it_index);
|
||||
return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index);
|
||||
}
|
||||
}
|
||||
/* empty iterator, create an empty list */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue