Skip to content

Fix bitset selection at the 32-bit rank boundary - #970

Merged
lemire merged 1 commit into
RoaringBitmap:masterfrom
perfloop-oss:perfloop-pr-open-b60mshfqpe
Dec 1, 2026
Merged

lemire merged 1 commit into
RoaringBitmap:masterfrom
perfloop-oss:perfloop-pr-open-b60mshfqpe

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

On a full 32-bit bitmap, roaring_bitmap_select silently returns false for every rank from 0xFFFF0000 through UINT32_MAX if the final container is stored as a bitset. An equal run-compressed bitmap returns those elements.

In C++, with exceptions enabled, Roaring64Map::select throws std::runtime_error ("Logic error: bitmap.select() returned false despite rank < cardinality()") for these ranks when a 32-bit sub-bitmap is full.

The final container starts at rank 4294901760 and contains 65536 values. Its exclusive end is 4294967296, which wraps to zero in the old 32-bit sum. The range check now compares a widened unsigned rank difference with cardinality, avoiding the overflowing sum. Ranks below *start_rank now return false instead of reaching assert(false). The selection loop and successful accumulator updates are unchanged.

The regression in tests/toplevel_unit.c builds the full bitmap with a compact run prefix and a bitset tail. tests/bitset_container_unit.c checks end-of-domain ranks, lower-bound rejection, and the existing false-return accumulator behavior.

ctest’s focused selection runs passed: three suites, zero failed, zero skipped (seven cmocka tests), in a Debug build with -DROARING_SANITIZE=ON -DROARING_SANITIZE_UNDEFINED=ON; both new tests fail without the fix.

Formatting checked with clang-format 17.

AI assistance: Perfloop generated the fix, tests, and this description.

cc @lemire

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

@lemire
lemire merged commit 06298c5 into RoaringBitmap:master Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants