buzhash chunkers: add len==0 check to avoid buffer over-read

Isn't called by the higher level code with len==0,
but adding the check nevertheless for cleaner and
less suspicious code.
This commit is contained in:
Thomas Waldmann 2026-05-12 17:30:07 +02:00
parent f94e3dea95
commit b362b0898e
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01
2 changed files with 4 additions and 0 deletions

View file

@ -101,6 +101,8 @@ cdef uint32_t _buzhash(const unsigned char* data, size_t len, const uint32_t* h)
"""Calculate the buzhash of the given data."""
cdef uint32_t i
cdef uint32_t sum = 0, imod
if len == 0:
return 0
for i in range(len - 1, 0, -1):
imod = i & 0x1f
sum ^= BARREL_SHIFT(h[data[0]], imod)

View file

@ -78,6 +78,8 @@ cdef uint64_t _buzhash64(const unsigned char* data, size_t len, const uint64_t*
"""Calculate the buzhash of the given data."""
cdef uint64_t i
cdef uint64_t sum = 0, imod
if len == 0:
return 0
for i in range(len - 1, 0, -1):
imod = i & 0x3f
sum ^= BARREL_SHIFT64(h[data[0]], imod)