From: Raymond Hettinger Date: Tue, 12 May 2015 02:58:56 +0000 (-0700) Subject: Defend against a mutation during comparison X-Git-Tag: v3.5.0b1~202^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9db9e152f3325b075e59ef4fdecfd0b9ec4746c;p=thirdparty%2FPython%2Fcpython.git Defend against a mutation during comparison --- diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 38bcdbe72cf1..04845f165aa4 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);