[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:
Miss Islington (bot) 2025-01-18 11:14:07 +01:00 committed by GitHub
parent 8a8f5d636d
commit 405f6d72bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

View file

@ -1609,5 +1609,13 @@ class LargeArrayTest(unittest.TestCase):
self.assertEqual(ls[:8], list(example[:8]))
self.assertEqual(ls[-8:], list(example[-8:]))
def test_gh_128961(self):
a = array.array('i')
it = iter(a)
list(it)
it.__setstate__(0)
self.assertRaises(StopIteration, next, it)
if __name__ == "__main__":
unittest.main()