diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-07-13 13:05:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-13 13:05:44 (GMT) |
commit | f56c75ed53dcad4d59dff4377ae463d6b96acd3e (patch) | |
tree | b96079d403fc15668db01f08acdd602c9f3cbefe /Lib | |
parent | c77f71f9819022fa3adeb2f710e564a392ff24c6 (diff) | |
download | cpython-f56c75ed53dcad4d59dff4377ae463d6b96acd3e.zip cpython-f56c75ed53dcad4d59dff4377ae463d6b96acd3e.tar.gz cpython-f56c75ed53dcad4d59dff4377ae463d6b96acd3e.tar.bz2 |
bpo-41288: Fix a crash in unpickling invalid NEWOBJ_EX. (GH-21458)
Automerge-Triggered-By: @tiran
(cherry picked from commit 4f309abf55f0e6f8950ac13d6ec83c22b8d47bf8)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/pickletester.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 9401043..ff7bbb0 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1170,6 +1170,24 @@ class AbstractUnpickleTests(unittest.TestCase): self.assertIs(type(unpickled), collections.UserDict) self.assertEqual(unpickled, collections.UserDict({1: 2})) + def test_bad_reduce(self): + self.assertEqual(self.loads(b'cbuiltins\nint\n)R.'), 0) + self.check_unpickling_error(TypeError, b'N)R.') + self.check_unpickling_error(TypeError, b'cbuiltins\nint\nNR.') + + def test_bad_newobj(self): + error = (pickle.UnpicklingError, TypeError) + self.assertEqual(self.loads(b'cbuiltins\nint\n)\x81.'), 0) + self.check_unpickling_error(error, b'cbuiltins\nlen\n)\x81.') + self.check_unpickling_error(error, b'cbuiltins\nint\nN\x81.') + + def test_bad_newobj_ex(self): + error = (pickle.UnpicklingError, TypeError) + self.assertEqual(self.loads(b'cbuiltins\nint\n)}\x92.'), 0) + self.check_unpickling_error(error, b'cbuiltins\nlen\n)}\x92.') + self.check_unpickling_error(error, b'cbuiltins\nint\nN}\x92.') + self.check_unpickling_error(error, b'cbuiltins\nint\n)N\x92.') + def test_bad_stack(self): badpickles = [ b'.', # STOP |