diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-17 20:15:53 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-10-17 20:15:53 (GMT) |
commit | 87eee631fb1ae38aa15ebd9741a1af82dd7b4ea0 (patch) | |
tree | 0c7161ab30734ac3244aea50e6417d7c2ed913ea /Lib/test/pickletester.py | |
parent | 869bad9b5a4a51640ee97deda95913899c663333 (diff) | |
download | cpython-87eee631fb1ae38aa15ebd9741a1af82dd7b4ea0.zip cpython-87eee631fb1ae38aa15ebd9741a1af82dd7b4ea0.tar.gz cpython-87eee631fb1ae38aa15ebd9741a1af82dd7b4ea0.tar.bz2 |
#3664: The pickle module could segfault if a Pickler instance is not correctly initialized:
when a subclass forgets to call the base __init__ method,
or when __init__ is called a second time with invalid parameters
Patch by Alexandre Vassalotti.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index a622145..4c301ad 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -996,6 +996,20 @@ class AbstractPickleModuleTests(unittest.TestCase): pickle.Pickler(f, -1) pickle.Pickler(f, protocol=-1) + def test_bad_init(self): + # Test issue3664 (pickle can segfault from a badly initialized Pickler). + from io import BytesIO + # Override initialization without calling __init__() of the superclass. + class BadPickler(pickle.Pickler): + def __init__(self): pass + + class BadUnpickler(pickle.Unpickler): + def __init__(self): pass + + self.assertRaises(pickle.PicklingError, BadPickler().dump, 0) + self.assertRaises(pickle.UnpicklingError, BadUnpickler().load) + + class AbstractPersistentPicklerTests(unittest.TestCase): # This class defines persistent_id() and persistent_load() |