From b9db9e152f3325b075e59ef4fdecfd0b9ec4746c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Mon, 11 May 2015 19:58:56 -0700 Subject: [PATCH] Defend against a mutation during comparison --- Modules/_heapqmodule.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 38bcdbe72cf..04845f165aa 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -224,6 +224,11 @@ heappushpop(PyObject *self, PyObject *args) return item; } + if (PyList_GET_SIZE(heap) == 0) { + PyErr_SetString(PyExc_IndexError, "index out of range"); + return NULL; + } + returnitem = PyList_GET_ITEM(heap, 0); Py_INCREF(item); PyList_SET_ITEM(heap, 0, item);