Skip to content

[Bug] BE crashes (core dump) when explode_bitmap is called on a bitmap with cardinality exceeding INT_MAX #66033

Description

@Baymine

Search before asking

  • I had searched in the issues and found no similar issues.

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?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions