]> arthur.barton.de Git - bup.git/commitdiff
bitmatch: check for overflow via intprops
authorRob Browning <rlb@defaultvalue.org>
Fri, 8 Oct 2021 15:47:28 +0000 (10:47 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sat, 16 Oct 2021 19:32:42 +0000 (14:32 -0500)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/_helpers.c

index fc1b69b75b45832614447ba29f9d701d3a1bbf24..b5a3c799489e72d051e4735e2207c75e91196a11 100644 (file)
@@ -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);
 }
 
 
 }