diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-30 21:18:34 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-30 21:18:34 (GMT) |
commit | 69a9c5b539dd848369efcd67574e447065f638e9 (patch) | |
tree | 8c1ad2e3831296822c6367a50e57e68a188edbc5 /Lib/test | |
parent | 1fac5a450562c50a3b7121598da7f010a306e50f (diff) | |
download | cpython-69a9c5b539dd848369efcd67574e447065f638e9.zip cpython-69a9c5b539dd848369efcd67574e447065f638e9.tar.gz cpython-69a9c5b539dd848369efcd67574e447065f638e9.tar.bz2 |
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)
A list is not an iterator...
Will backport to 2.6 and 2.5.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index e1bc078..bf9bca7 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): |