gh-128961: Fix exhausted array iterator crash in __setstate__() (#128962)

This commit is contained in:
Tomasz Pytel 2025-01-18 04:55:29 -05:00 committed by GitHub
parent 9ed7bf2cd7
commit 4dade055f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View file

@ -3090,11 +3090,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
Py_ssize_t index = PyLong_AsSsize_t(state);
if (index == -1 && PyErr_Occurred())
return NULL;
if (index < 0)
index = 0;
else if (index > Py_SIZE(self->ao))
index = Py_SIZE(self->ao); /* iterator exhausted */
self->index = index;
arrayobject *ao = self->ao;
if (ao != NULL) {
if (index < 0) {
index = 0;
}
else if (index > Py_SIZE(ao)) {
index = Py_SIZE(ao); /* iterator exhausted */
}
self->index = index;
}
Py_RETURN_NONE;
}