mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
#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.
This commit is contained in:
parent
869bad9b5a
commit
87eee631fb
3 changed files with 33 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue