summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorŁukasz Langa <lukasz@langa.pl>2013-07-01 14:03:17 (GMT)
committerŁukasz Langa <lukasz@langa.pl>2013-07-01 14:03:17 (GMT)
commit7c1457bed24f06cf793fee4536301540b5d327d4 (patch)
treecea3bd89ef5f714605b7cc76fd7670f5ebbe5c90
parent3720c77e307781b1e9f459a8e7844fceacef5cba (diff)
parent54882bfc18732bb1e5360bbc2e99ef0409ea4e51 (diff)
downloadcpython-7c1457bed24f06cf793fee4536301540b5d327d4.zip
cpython-7c1457bed24f06cf793fee4536301540b5d327d4.tar.gz
cpython-7c1457bed24f06cf793fee4536301540b5d327d4.tar.bz2
Merge with current default
-rw-r--r--Lib/test/test_pickle.py7
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_pickle.c5
3 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py
index f52d4bd..e96fe52 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):
diff --git a/Misc/NEWS b/Misc/NEWS
index 92d7c39..ed51b38 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -135,6 +135,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 18240: The HMAC module is no longer restricted to bytes and accepts
any bytes-like object, e.g. memoryview. Original patch by Jonas Borgström.
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 002b378..5b30931 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -5952,6 +5952,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,
+ "memo key must be positive integers.");
+ goto error;
+ }
if (_Unpickler_MemoPut(self, idx, value) < 0)
goto error;
}