Commit 3c40a0b6 authored by Philip Pronin's avatar Philip Pronin Committed by Jordan DeLong

fix heap-buffer-overflow (asan) in EliasFanoCoding

Test Plan:
fbconfig folly/experimental/test:elias_fano_test && fbmake runtests_opt

Reviewed By: tudorb@fb.com

FB internal diff: D962971
parent ec0da690
......@@ -132,13 +132,15 @@ struct EliasFanoCompressedList {
// *** Lower bits.
const size_t lowerSize = (numLowerBits * size + 7) / 8;
unsigned char* const lower =
static_cast<unsigned char*>(calloc(lowerSize + 7, 1));
unsigned char* lower = nullptr;
if (lowerSize > 0) { // numLowerBits != 0
lower = static_cast<unsigned char*>(calloc(lowerSize + 7, 1));
const ValueType lowerMask = (ValueType(1) << numLowerBits) - 1;
for (size_t i = 0; i < size; ++i) {
const ValueType lowerBits = list[i] & lowerMask;
writeBits56(lower, i * numLowerBits, numLowerBits, lowerBits);
}
}
// *** Upper bits.
// Upper bits are stored using unary delta encoding.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment