Skip to content

Commit

Permalink
[BugFix]fix out-of-bound access for bit unpacking with simd (StarRock…
Browse files Browse the repository at this point in the history
…s#52807)

Signed-off-by: zombee0 <ewang2027@gmail.com>
Co-authored-by: alvin <115669851+alvin-celerdata@users.noreply.github.com>
  • Loading branch information
zombee0 and alvin-celerdata authored Nov 12, 2024
1 parent 66e6471 commit 4979bd8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions be/src/util/bit_packing_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class BitPackingAdapter {
// the prior (x - 1) batch has used (x - 1) * bit_width bytes, and the last batch use
// (bit_width + 7) / 8 * 8 bytes, so there should be
// (x - 1) * bit_width + (bit_width + 7) / 8 <= in_bytes
const int64_t batches_to_read = std::max(
(int64_t)0,
std::min((in_bytes - (bit_width + 7) / 8 * 8) / bit_width + 1, values_to_read / BATCH_SIZE));
const int64_t batches_to_read = (in_bytes > (bit_width + 7) / 8 * 8)
? std::min((in_bytes - (bit_width + 7) / 8 * 8) / bit_width + 1,
values_to_read / BATCH_SIZE)
: 0;

if (batches_to_read > 0) {
starrocks::util::unpack(bit_width, in, in_bytes, batches_to_read * BATCH_SIZE, out);
Expand Down

0 comments on commit 4979bd8

Please sign in to comment.