mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
[3.12] gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128977)
(cherry picked from commit 4dade055f4
)
Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
This commit is contained in:
parent
8a8f5d636d
commit
405f6d72bb
3 changed files with 19 additions and 5 deletions
|
@ -2966,11 +2966,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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue