diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-21 20:50:25 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-21 20:50:25 +0300 |
commit | 4faf5c5655277cec99b2b11f7fe34e73d3ae28b9 (patch) | |
tree | aefe265087e545e5277383bf21d90ced3cdf4022 /Lib | |
parent | cbfe07e06cb460986b37604bc32dad407cb33f62 (diff) | |
download | cpython-git-4faf5c5655277cec99b2b11f7fe34e73d3ae28b9.tar.gz |
Issue #23985: Fixed integer overflow in iterator object. Patch by
Clement Rouault.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_iter.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py index e06f239dda..abc408f869 100644 --- a/Lib/test/test_iter.py +++ b/Lib/test/test_iter.py @@ -1,5 +1,6 @@ # Test iterators. +import sys import unittest from test.support import run_unittest, TESTFN, unlink, cpython_only import pickle @@ -48,6 +49,10 @@ class SequenceClass: else: raise IndexError +class UnlimitedSequenceClass: + def __getitem__(self, i): + return i + # Main test suite class TestCase(unittest.TestCase): @@ -919,6 +924,26 @@ class TestCase(unittest.TestCase): lst.extend(gen()) self.assertEqual(len(lst), 760) + @cpython_only + def test_iter_overflow(self): + # Test for the issue 22939 + it = iter(UnlimitedSequenceClass()) + # Manually set `it_index` to PY_SSIZE_T_MAX-2 without a loop + it.__setstate__(sys.maxsize - 2) + self.assertEqual(next(it), sys.maxsize - 2) + self.assertEqual(next(it), sys.maxsize - 1) + with self.assertRaises(OverflowError): + next(it) + # Check that Overflow error is always raised + with self.assertRaises(OverflowError): + next(it) + + def test_iter_neg_setstate(self): + it = iter(UnlimitedSequenceClass()) + it.__setstate__(-42) + self.assertEqual(next(it), 0) + self.assertEqual(next(it), 1) + def test_main(): run_unittest(TestCase) |