From 6f03b236c17c96bc9f8a004ffa7e7ae0542e9cac Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Sun, 24 Nov 2019 20:15:08 +0100 Subject: bpo-38876: Raise pickle.UnpicklingError when loading an item from memo for invalid input (GH-17335) The previous code was raising a `KeyError` for both the Python and C implementation. This was caused by the specified index of an invalid input which did not exist in the memo structure, where the pickle stores what objects it has seen. The malformed input would have caused either a `BINGET` or `LONG_BINGET` load from the memo, leading to a `KeyError` as the determined index was bogus. https://bugs.python.org/issue38876 https://bugs.python.org/issue38876 --- Lib/test/pickletester.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Lib/test/pickletester.py') diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index c9f374678a..953fd5c5a2 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1019,7 +1019,9 @@ class AbstractUnpickleTests(unittest.TestCase): self.assertEqual(self.loads(dumped), '\u20ac\x00') def test_misc_get(self): - self.check_unpickling_error(KeyError, b'g0\np0') + self.check_unpickling_error(pickle.UnpicklingError, b'g0\np0') + self.check_unpickling_error(pickle.UnpicklingError, b'jens:') + self.check_unpickling_error(pickle.UnpicklingError, b'hens:') self.assert_is_copy([(100,), (100,)], self.loads(b'((Kdtp0\nh\x00l.))')) -- cgit v1.2.1