diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -493,6 +493,11 @@ static PyObject *parse_dirstate(PyObject /* read filenames */ while (pos >= 40 && pos < len) { + if (pos + 17 > len) { + PyErr_SetString(PyExc_ValueError, + "overflow in dirstate"); + goto quit; + } cur = str + pos; /* unpack header */ state = *cur;