Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit405f6d7

Browse files
[3.12]gh-128961: Fix exhausted array iterator crash in __setstate__() (GH-128962) (#128977)
(cherry picked from commit4dade05)Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
1 parent8a8f5d6 commit405f6d7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

‎Lib/test/test_array.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,5 +1609,13 @@ def test_tolist(self, size):
16091609
self.assertEqual(ls[:8],list(example[:8]))
16101610
self.assertEqual(ls[-8:],list(example[-8:]))
16111611

1612+
deftest_gh_128961(self):
1613+
a=array.array('i')
1614+
it=iter(a)
1615+
list(it)
1616+
it.__setstate__(0)
1617+
self.assertRaises(StopIteration,next,it)
1618+
1619+
16121620
if__name__=="__main__":
16131621
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a crash when setting state on an exhausted:class:`array.array` iterator.

‎Modules/arraymodule.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,11 +2966,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
29662966
Py_ssize_tindex=PyLong_AsSsize_t(state);
29672967
if (index==-1&&PyErr_Occurred())
29682968
returnNULL;
2969-
if (index<0)
2970-
index=0;
2971-
elseif (index>Py_SIZE(self->ao))
2972-
index=Py_SIZE(self->ao);/* iterator exhausted */
2973-
self->index=index;
2969+
arrayobject*ao=self->ao;
2970+
if (ao!=NULL) {
2971+
if (index<0) {
2972+
index=0;
2973+
}
2974+
elseif (index>Py_SIZE(ao)) {
2975+
index=Py_SIZE(ao);/* iterator exhausted */
2976+
}
2977+
self->index=index;
2978+
}
29742979
Py_RETURN_NONE;
29752980
}
29762981

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp