Author: Armin Rigo <[email protected]>
Branch:
Changeset: r81597:5460d8ed7191
Date: 2016-01-06 13:20 +0100
http://bitbucket.org/pypy/pypy/changeset/5460d8ed7191/
Log: Crash with the same UnpicklingError as CPython when asked to
unpickle a string with an invalid load key
diff --git a/lib_pypy/cPickle.py b/lib_pypy/cPickle.py
--- a/lib_pypy/cPickle.py
+++ b/lib_pypy/cPickle.py
@@ -167,7 +167,11 @@
try:
key = ord(self.read(1))
while key != STOP:
- self.dispatch[key](self)
+ try:
+ meth = self.dispatch[key]
+ except KeyError:
+ raise UnpicklingError("invalid load key, '%s'." % chr(key))
+ meth(self)
key = ord(self.read(1))
except TypeError:
if self.read(1) == '':
diff --git a/pypy/module/test_lib_pypy/test_cPickle.py
b/pypy/module/test_lib_pypy/test_cPickle.py
--- a/pypy/module/test_lib_pypy/test_cPickle.py
+++ b/pypy/module/test_lib_pypy/test_cPickle.py
@@ -5,3 +5,7 @@
def test_stack_underflow():
py.test.raises(cPickle.UnpicklingError, cPickle.loads, "a string")
+
+def test_bad_key():
+ e = py.test.raises(cPickle.UnpicklingError, cPickle.loads, "v")
+ assert str(e.value) == "invalid load key, 'v'."
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit