Skip to content

roaring_bridge: Go back to collect() in RoaringBitmap32::ToVec - #280

Open
dhivadhiva wants to merge 1 commit into
google:mainfrom
dhivadhiva:roaring-tovec-overflow
Open

dhivadhiva wants to merge 1 commit into
google:mainfrom
dhivadhiva:roaring-tovec-overflow

Conversation

@dhivadhiva

Copy link
Copy Markdown
Contributor

473adb3 ("Improve performance for ToVec") brought back the Iter::next_many version of RoaringBitmap32::ToVec, which 69847f6 had undone because of RoaringBitmap/roaring-rs#403. That issue is still open, its fix (RoaringBitmap/roaring-rs#404) is not merged, and roaring 0.12.0 is still the latest release, so ToVec is broken on main again.

The bug

next_many computes the length of a run as a u16 (interval_store.rs:894), which overflows for a run container that covers all 65536 values of its key:

RoaringBitmap32 bm;
bm.InsertRange(0, 70000);
bm.ToVec();
  • In a release build, it returns 70000 values that start 65536, 65537, … and end in 65536 zeros. Only 4464 of them get filled.
  • In a debug build (what this repo's CMake builds by default), it panics with attempt to add with overflow, and the panic aborts the process because it can't unwind through the Crubit thunk.
  • Untrusted input reaches it too: the 15-byte serialized form of 0..65535 (3B 30 00 00 01 00 00 FF FF 01 00 00 00 FF FF) passes Deserialize(), and ToVec() on the result fills none of the 65536 values.

RoaringBitmap64::ToVec and the begin()/end() iterators still use next() and are not affected.

Fix

ToVec collects through the iterator again, as RoaringBitmap64::ToVec does. A comment points at the upstream issue, so next_many can come back once a fixed roaring release can be required.

Testing

Two new tests in roaring_bridge_cc_test:

  • RoaringBitmapTest/*.ToVecWithFullRunContainer: InsertRange(0, 70000), then compare ToVec() with 0..69999, for both bitmap types.
  • RoaringBitmap32Test.ToVecAfterDeserializingFullRunContainer: deserialize the 15 bytes above, then compare ToVec() with 0..65535.

On main, both 32-bit cases abort with the overflow panic, which stops the whole test binary. With this change, all 45 tests pass. Built with the CI recipe (cmake -B build -S roaring_bridge, Crubit b715411, nightly-2026-11-11), and ctest runs these tests in CI.

473adb3 switched ToVec to Iter::next_many again, after 69847f6 had
undone the same change because of
RoaringBitmap/roaring-rs#403. That issue is
still open and roaring 0.12.0 is the latest release, so the bug is back:
next_many computes the length of a run as a u16, which overflows for a
run container that covers all 65536 values of its key.

    RoaringBitmap32 bm;
    bm.InsertRange(0, 70000);
    bm.ToVec();

In a release build this returns 70000 values that start at 65536 and end
in zeros. In a debug build, which is what this repo's CMake builds by
default, the overflow panics, and the panic aborts the process. The
15-byte serialized form of 0..65535 does the same through Deserialize().

Collect through the iterator again, as RoaringBitmap64::ToVec does, and
add tests for both cases.
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.

1 participant