diff options
author | Kristján Valur Jónsson <sweskman@gmail.com> | 2015-09-12 15:20:54 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <sweskman@gmail.com> | 2015-09-12 15:20:54 (GMT) |
commit | 102764a1f6927955b9a907005ffd07216ebe1d96 (patch) | |
tree | 32b516565947c7d9ff51ae5c40abc14e8bac7003 /Lib | |
parent | a82f77fb00ca3bd3eb27a6a5d77a19eadcf0ba31 (diff) | |
download | cpython-102764a1f6927955b9a907005ffd07216ebe1d96.zip cpython-102764a1f6927955b9a907005ffd07216ebe1d96.tar.gz cpython-102764a1f6927955b9a907005ffd07216ebe1d96.tar.bz2 |
Issue #25021: Correctly make sure that product.__setstate__ does not access
invalid memory.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_itertools.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index bb3b61f..35391c9 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -959,6 +959,16 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(list(copy.deepcopy(product(*args))), result) self.pickletest(product(*args)) + def test_product_issue_25021(self): + # test that indices are properly clamped to the length of the tuples + p = product((1, 2),(3,)) + p.__setstate__((0, 0x1000)) # will access tuple element 1 if not clamped + self.assertEqual(next(p), (2, 3)) + # test that empty tuple in the list will result in an immediate StopIteration + p = product((1, 2), (), (3,)) + p.__setstate__((0, 0, 0x1000)) # will access tuple element 1 if not clamped + self.assertRaises(StopIteration, next, p) + def test_repeat(self): self.assertEqual(list(repeat(object='a', times=3)), ['a', 'a', 'a']) self.assertEqual(lzip(range(3),repeat('a')), |