summaryrefslogtreecommitdiffstats
path: root/Lib/test/pickletester.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-23 13:17:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-23 13:17:43 (GMT)
commite9b3074cf931fee3cb91638cbdd694fa9eb9614b (patch)
tree15dcac1d410ece6390346e8d58a4b416d5dd37f4 /Lib/test/pickletester.py
parentb6aa5375d5a2f81370338357506034befe62aa31 (diff)
downloadcpython-e9b3074cf931fee3cb91638cbdd694fa9eb9614b.zip
cpython-e9b3074cf931fee3cb91638cbdd694fa9eb9614b.tar.gz
cpython-e9b3074cf931fee3cb91638cbdd694fa9eb9614b.tar.bz2
Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r--Lib/test/pickletester.py85
1 files changed, 84 insertions, 1 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index e852b01..cd2423f 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -12,7 +12,7 @@ import weakref
from http.cookies import SimpleCookie
from test.support import (
- TestFailed, TESTFN, run_with_locale, no_tracing,
+ TestFailed, TESTFN, run_with_locale, no_tracing, captured_stdout,
_2G, _4G, bigmemtest,
)
@@ -987,6 +987,89 @@ class AbstractUnpickleTests(unittest.TestCase):
self.assertIs(type(unpickled), collections.UserDict)
self.assertEqual(unpickled, collections.UserDict({1: 2}))
+ def test_bad_stack(self):
+ badpickles = [
+ b'0.', # POP
+ b'1.', # POP_MARK
+ b'2.', # DUP
+ # b'(2.', # PyUnpickler doesn't raise
+ b'R.', # REDUCE
+ b')R.',
+ b'a.', # APPEND
+ b'Na.',
+ b'b.', # BUILD
+ b'Nb.',
+ b'd.', # DICT
+ b'e.', # APPENDS
+ # b'(e.', # PyUnpickler raises AttributeError
+ b'ibuiltins\nlist\n.', # INST
+ b'l.', # LIST
+ b'o.', # OBJ
+ b'(o.',
+ b'p1\n.', # PUT
+ b'q\x00.', # BINPUT
+ b'r\x00\x00\x00\x00.', # LONG_BINPUT
+ b's.', # SETITEM
+ b'Ns.',
+ b'NNs.',
+ b't.', # TUPLE
+ b'u.', # SETITEMS
+ b'(u.',
+ b'}(Nu.',
+ b'\x81.', # NEWOBJ
+ b')\x81.',
+ b'\x85.', # TUPLE1
+ b'\x86.', # TUPLE2
+ b'N\x86.',
+ b'\x87.', # TUPLE3
+ b'N\x87.',
+ b'NN\x87.',
+ b'\x90.', # ADDITEMS
+ # b'(\x90.', # PyUnpickler raises AttributeError
+ b'\x91.', # FROZENSET
+ b'\x92.', # NEWOBJ_EX
+ b')}\x92.',
+ b'\x93.', # STACK_GLOBAL
+ b'Vlist\n\x93.',
+ b'\x94.', # MEMOIZE
+ ]
+ for p in badpickles:
+ with self.subTest(p):
+ self.assertRaises(self.bad_stack_errors, self.loads, p)
+
+ def test_bad_mark(self):
+ badpickles = [
+ b'cbuiltins\nlist\n)(R.', # REDUCE
+ b'cbuiltins\nlist\n()R.',
+ b']N(a.', # APPEND
+ b'cbuiltins\nValueError\n)R}(b.', # BUILD
+ b'cbuiltins\nValueError\n)R(}b.',
+ b'(Nd.', # DICT
+ b'}NN(s.', # SETITEM
+ b'}N(Ns.',
+ b'cbuiltins\nlist\n)(\x81.', # NEWOBJ
+ b'cbuiltins\nlist\n()\x81.',
+ b'N(\x85.', # TUPLE1
+ b'NN(\x86.', # TUPLE2
+ b'N(N\x86.',
+ b'NNN(\x87.', # TUPLE3
+ b'NN(N\x87.',
+ b'N(NN\x87.',
+ b'cbuiltins\nlist\n)}(\x92.', # NEWOBJ_EX
+ b'cbuiltins\nlist\n)(}\x92.',
+ b'cbuiltins\nlist\n()}\x92.',
+ b'Vbuiltins\n(Vlist\n\x93.', # STACK_GLOBAL
+ b'Vbuiltins\nVlist\n(\x93.',
+ ]
+ for p in badpickles:
+ # PyUnpickler prints reduce errors to stdout
+ with self.subTest(p), captured_stdout():
+ try:
+ self.loads(p)
+ except (IndexError, AttributeError, TypeError,
+ pickle.UnpicklingError):
+ pass
+
class AbstractPickleTests(unittest.TestCase):
# Subclass must define self.dumps, self.loads.