diff options
author | Christian Heimes <christian@cheimes.de> | 2013-07-01 15:17:45 +0200 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-07-01 15:17:45 +0200 |
commit | 9b605065aff8df83c32ef308a754272558e25ba2 (patch) | |
tree | cc1bc55af7865cec6e11c32e40780875e1aeb0eb | |
parent | 3a15fd50a72bcd52d34575fe96a28ad9f444306e (diff) | |
download | cpython-9b605065aff8df83c32ef308a754272558e25ba2.tar.gz |
Issue #18339: Negative ints keys in unpickler.memo dict no longer cause a
segfault inside the _pickle C extension.
-rw-r--r-- | Lib/test/test_pickle.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Modules/_pickle.c | 5 |
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index f52d4bdee9..e96fe523df 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -115,6 +115,13 @@ if has_c_implementation: pickler_class = _pickle.Pickler unpickler_class = _pickle.Unpickler + def test_issue18339(self): + unpickler = self.unpickler_class(io.BytesIO()) + self.assertRaises(TypeError, setattr, unpickler, "memo", object) + # used to cause a segfault + self.assertRaises(ValueError, setattr, unpickler, "memo", {-1: None}) + unpickler.memo = {1: None} + class CDispatchTableTests(AbstractDispatchTableTests): pickler_class = pickle.Pickler def get_dispatch_table(self): @@ -38,6 +38,9 @@ Core and Builtins Library ------- +- Issue #18339: Negative ints keys in unpickler.memo dict no longer cause a + segfault inside the _pickle C extension. + - Issue #18224: Removed pydoc script from created venv, as it causes problems on Windows and adds no value over and above python -m pydoc ... diff --git a/Modules/_pickle.c b/Modules/_pickle.c index a8d6684b7c..195ee5d790 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -5931,6 +5931,11 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj) idx = PyLong_AsSsize_t(key); if (idx == -1 && PyErr_Occurred()) goto error; + if (idx < 0) { + PyErr_SetString(PyExc_ValueError, + "memos key must be positive integers."); + goto error; + } if (_Unpickler_MemoPut(self, idx, value) < 0) goto error; } |