Skip to content

[C++] SetBitRunReader fails on large unaligned bitmap slices #55945

Done

Description

@HuaHuaY

Describe the bug, including details regarding any error messages, version, and platform.

SetBitRunReader narrows the slice length to int32_t before computing how many bits to read from the first byte. For a slice starting at bit offset 3 with a length of 2^31 bits, it should read 5 bits from that byte. Instead, the narrowed length is negative and a Debug build fails the num_bits > 0 assertion in LoadPartialWord().

ReverseSetBitRunReader has the same issue at the other end of the slice.

We can test by

TEST_F(TestSetBitRunReader, LargeUnalignedSlice) {
  constexpr int64_t kLength = int64_t{1} << 31;
  constexpr int64_t kOffset = 3;
  ASSERT_OK_AND_ASSIGN(auto bitmap, AllocateBitmap(kOffset + kLength));
  // Each reader's first run ends within its initial partial byte.
  bitmap->mutable_data()[0] = 0b00001000;
  bitmap->mutable_data()[bitmap->size() - 1] = 0b00000100;

  SetBitRunReader forward(bitmap->data(), kOffset, kLength);
  EXPECT_EQ(forward.NextRun(), (SetBitRun{0, 1}));
  ReverseSetBitRunReader reverse(bitmap->data(), kOffset, kLength);
  EXPECT_EQ(reverse.NextRun(), (SetBitRun{kLength - 1, 1}));
}

Component(s)

C++

Activity

  1. self-assigned this
    on Dec 3, 2026
  2. added a commit that references this issue on Dec 3, 2026
  3. added this to the 27.0.0 milestone on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions