From: Rob Browning Date: Fri, 8 Oct 2021 15:47:28 +0000 (-0500) Subject: bitmatch: check for overflow via intprops X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=8659febe534245ed8a5299637aa4ee0961aa1011 bitmatch: check for overflow via intprops Signed-off-by: Rob Browning --- diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c index fc1b69b..b5a3c79 100644 --- a/lib/bup/_helpers.c +++ b/lib/bup/_helpers.c @@ -620,8 +620,14 @@ static PyObject *bitmatch(PyObject *self, PyObject *args) } } - assert(byte <= (INT_MAX >> 3)); - return Py_BuildValue("i", byte*8 + bit); + unsigned long long result; + if (!INT_MULTIPLY_OK(byte, 8, &result) + || !INT_ADD_OK(result, bit, &result)) + { + PyErr_Format(PyExc_OverflowError, "bitmatch bit count too large"); + return NULL; + } + return PyLong_FromUnsignedLongLong(result); }