X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=blobdiff_plain;f=lib%2Fbup%2F_helpers.c;h=cf31d0aac2630eb44f35398dfa66e12f058875ad;hp=ba8cd6035b6e8ecbf70d66b0d4175a9c3c58a068;hb=5d153a347a2732fc117c655f842f019c5e52877c;hpb=9c4acb514533925ccbfa6b5ceb88876fb36cb819 diff --git a/lib/bup/_helpers.c b/lib/bup/_helpers.c index ba8cd60..cf31d0a 100644 --- a/lib/bup/_helpers.c +++ b/lib/bup/_helpers.c @@ -1087,7 +1087,7 @@ static PyObject *write_idx(PyObject *self, PyObject *args) PyObject *part; unsigned int total = 0; uint32_t count; - int i, j, ofs64_count; + int i, ofs64_count; uint32_t *fan_ptr, *crc_ptr, *ofs_ptr; uint64_t *ofs64_ptr; struct sha *sha_ptr; @@ -1122,16 +1122,17 @@ static PyObject *write_idx(PyObject *self, PyObject *args) ofs64_count = 0; for (i = 0; i < FAN_ENTRIES; ++i) { - Py_ssize_t plen; part = PyList_GET_ITEM(idx, i); PyList_Sort(part); - plen = PyList_GET_SIZE(part); - if (plen > UINT32_MAX || UINT32_MAX - count < plen) { + uint32_t plen; + if (!INTEGRAL_ASSIGNMENT_FITS(&plen, PyList_GET_SIZE(part)) + || UINT32_MAX - count < plen) { PyErr_Format(PyExc_OverflowError, "too many objects in index part"); goto clean_and_return; } - count += (uint32_t) plen; + count += plen; *fan_ptr++ = htonl(count); + uint32_t j; for (j = 0; j < plen; ++j) { unsigned char *sha = NULL;