Search before asking
Version
master / 4.0
What's Wrong?
When the explode_bitmap table function processes a bitmap whose cardinality exceeds INT_MAX (more than ~2.1 billion elements), the BE crashes with a core dump.
In VExplodeBitmapTableFunction::get_value (be/src/exprs/table_function/vexplode_bitmap.cpp) the number of rows to emit is computed as:
max_step = std::min(max_step, (int)(_cur_size - _cur_offset));
_cur_size (the bitmap cardinality) and _cur_offset are both int64_t. When _cur_size - _cur_offset is larger than INT_MAX, the C-style (int) cast overflows and produces a negative max_step. That negative value then flows into target->resize(origin_size + max_step), underflowing the size computation and crashing the BE.
What You Expected?
explode_bitmap should correctly explode very large bitmaps (or at minimum not crash the BE) instead of overflowing the row-count computation.
How to Reproduce?
Call explode_bitmap on a BITMAP whose cardinality exceeds INT_MAX (~2.1 billion distinct values). Note this needs a very large bitmap (~16GB of memory) to actually trip the overflow, so it is hard to reproduce on modest hardware; the defect is evident from the code path regardless.
Anything Else?
The std::min should be evaluated in int64_t space and only cast back to int once it is provably within range.
Are you willing to submit PR?
Code of Conduct
Search before asking
Version
master / 4.0
What's Wrong?
When the
explode_bitmaptable function processes a bitmap whose cardinality exceedsINT_MAX(more than ~2.1 billion elements), the BE crashes with a core dump.In
VExplodeBitmapTableFunction::get_value(be/src/exprs/table_function/vexplode_bitmap.cpp) the number of rows to emit is computed as:_cur_size(the bitmap cardinality) and_cur_offsetare bothint64_t. When_cur_size - _cur_offsetis larger thanINT_MAX, the C-style(int)cast overflows and produces a negativemax_step. That negative value then flows intotarget->resize(origin_size + max_step), underflowing the size computation and crashing the BE.What You Expected?
explode_bitmapshould correctly explode very large bitmaps (or at minimum not crash the BE) instead of overflowing the row-count computation.How to Reproduce?
Call
explode_bitmapon aBITMAPwhose cardinality exceedsINT_MAX(~2.1 billion distinct values). Note this needs a very large bitmap (~16GB of memory) to actually trip the overflow, so it is hard to reproduce on modest hardware; the defect is evident from the code path regardless.Anything Else?
The
std::minshould be evaluated inint64_tspace and only cast back tointonce it is provably within range.Are you willing to submit PR?
Code of Conduct