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

Commitc75894a

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

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
@@ -1665,5 +1665,13 @@ def test_tolist(self, size):
16651665
self.assertEqual(ls[:8],list(example[:8]))
16661666
self.assertEqual(ls[-8:],list(example[-8:]))
16671667

1668+
deftest_gh_128961(self):
1669+
a=array.array('i')
1670+
it=iter(a)
1671+
list(it)
1672+
it.__setstate__(0)
1673+
self.assertRaises(StopIteration,next,it)
1674+
1675+
16681676
if__name__=="__main__":
16691677
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
@@ -3074,11 +3074,16 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
30743074
Py_ssize_tindex=PyLong_AsSsize_t(state);
30753075
if (index==-1&&PyErr_Occurred())
30763076
returnNULL;
3077-
if (index<0)
3078-
index=0;
3079-
elseif (index>Py_SIZE(self->ao))
3080-
index=Py_SIZE(self->ao);/* iterator exhausted */
3081-
self->index=index;
3077+
arrayobject*ao=self->ao;
3078+
if (ao!=NULL) {
3079+
if (index<0) {
3080+
index=0;
3081+
}
3082+
elseif (index>Py_SIZE(ao)) {
3083+
index=Py_SIZE(ao);/* iterator exhausted */
3084+
}
3085+
self->index=index;
3086+
}
30823087
Py_RETURN_NONE;
30833088
}
30843089

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp