diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-02 09:17:08 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-02 09:17:08 +0300 |
commit | 18c5e8e86f3ae2f67bbb893a5f89f9b4fb679f11 (patch) | |
tree | d445ea3c03083dc34db7c0164a5067004d035f63 /Lib/test | |
parent | 854adb1e0175dc915f5b611a2c780df6213d7c4b (diff) | |
parent | 8f0f2056499847999fffa7af7a8872500a191203 (diff) | |
download | cpython-git-18c5e8e86f3ae2f67bbb893a5f89f9b4fb679f11.tar.gz |
Issue #28322: Fixed possible crashes when unpickle itertools objects from
incorrect pickle data. Based on patch by John Leitch.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_itertools.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index d21d8ed32d..ea1f57caad 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -183,6 +183,19 @@ class TestBasicOps(unittest.TestCase): for proto in range(pickle.HIGHEST_PROTOCOL + 1): self.pickletest(proto, chain('abc', 'def'), compare=list('abcdef')) + def test_chain_setstate(self): + self.assertRaises(TypeError, chain().__setstate__, ()) + self.assertRaises(TypeError, chain().__setstate__, []) + self.assertRaises(TypeError, chain().__setstate__, 0) + self.assertRaises(TypeError, chain().__setstate__, ([],)) + self.assertRaises(TypeError, chain().__setstate__, (iter([]), [])) + it = chain() + it.__setstate__((iter(['abc', 'def']),)) + self.assertEqual(list(it), ['a', 'b', 'c', 'd', 'e', 'f']) + it = chain() + it.__setstate__((iter(['abc', 'def']), iter(['ghi']))) + self.assertEqual(list(it), ['ghi', 'a', 'b', 'c', 'd', 'e', 'f']) + def test_combinations(self): self.assertRaises(TypeError, combinations, 'abc') # missing r argument self.assertRaises(TypeError, combinations, 'abc', 2, 1) # too many arguments @@ -667,19 +680,22 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(take(20, c), list('defgabcdefgabcdefgab')) # The first argument to setstate needs to be a tuple - with self.assertRaises(SystemError): + with self.assertRaises(TypeError): cycle('defg').__setstate__([list('abcdefg'), 0]) # The first argument in the setstate tuple must be a list with self.assertRaises(TypeError): c = cycle('defg') - c.__setstate__((dict.fromkeys('defg'), 0)) - take(20, c) + c.__setstate__((tuple('defg'), 0)) + take(20, c) - # The first argument in the setstate tuple must be a list + # The second argument in the setstate tuple must be an int with self.assertRaises(TypeError): cycle('defg').__setstate__((list('abcdefg'), 'x')) + self.assertRaises(TypeError, cycle('').__setstate__, ()) + self.assertRaises(TypeError, cycle('').__setstate__, ([],)) + def test_groupby(self): # Check whether it accepts arguments correctly self.assertEqual([], list(groupby([]))) |