summaryrefslogtreecommitdiff
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 21:40:05 +0000
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-10-30 21:40:05 +0000
commit3b335ff3402b1263e3fbf50ef6ba6e8cf2de1624 (patch)
tree462aabe08d76fde7102cd80b9c2fa0259e5121d4 /Lib/test/pickletester.py
parent3e06faec4fa7e6afc266ca83ebd5444b1ddbc04a (diff)
downloadcpython-git-3b335ff3402b1263e3fbf50ef6ba6e8cf2de1624.tar.gz
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
does not return an iterator for the 4th and 5th items. (sequence-like and mapping-like state) Backport of r67049.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index e1bc078154..bf9bca78f9 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -849,6 +849,29 @@ class AbstractPickleTests(unittest.TestCase):
y = self.loads(s)
self.assertEqual(y._reduce_called, 1)
+ def test_reduce_bad_iterator(self):
+ # Issue4176: crash when 4th and 5th items of __reduce__()
+ # are not iterators
+ class C(object):
+ def __reduce__(self):
+ # 4th item is not an iterator
+ return list, (), None, [], None
+ class D(object):
+ def __reduce__(self):
+ # 5th item is not an iterator
+ return dict, (), None, None, []
+
+ # Protocol 0 is less strict and also accept iterables.
+ for proto in 0, 1, 2:
+ try:
+ self.dumps(C(), proto)
+ except (AttributeError, pickle.PickleError, cPickle.PickleError):
+ pass
+ try:
+ self.dumps(D(), proto)
+ except (AttributeError, pickle.PickleError, cPickle.PickleError):
+ pass
+
# Test classes for reduce_ex
class REX_one(object):