Skip to content

GH-55945: [C++] Clamp partial-byte lengths before narrowing in SetBitRunReader - #55946

Merged
HuaHuaY merged 1 commit into
apache:mainfrom
HuaHuaY:large_bitmap
Dec 3, 2026
Merged

HuaHuaY merged 1 commit into
apache:mainfrom
HuaHuaY:large_bitmap

Conversation

@HuaHuaY

@HuaHuaY HuaHuaY commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

SetBitRunReader narrows the slice length to int32_t before computing how many bits to read from a partial byte. For an unaligned slice of 2^31 bits, this produces a negative bit count and triggers a Debug assertion.

What changes are included in this PR?

Compute the minimum in int64_t before narrowing the result in both the forward and reverse readers.

Are these changes tested?

Yes.

Are there any user-facing changes?

No.

Was AI used for this PR?

In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings December 3, 2026 07:53
@HuaHuaY
HuaHuaY requested a review from wgtmac December 3, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Both reader directions still need a large-unaligned-slice regression test, since existing tests do not catch the narrowing bug at the 2^31-bit, offset-3 boundary.

1 open issue
What changed in this PR

Fixes Debug assertion failures when Arrow’s C++ bit-run readers process large, unaligned bitmap slices.

Changes:

  • Computes partial-byte lengths in int64_t before narrowing to int32_t, in both forward and reverse readers.
File Description
cpp/​src/​arrow/​util/​bit_run_reader.h Clamps partial-byte lengths before narrowing to avoid overflow.

Review effort: Balanced

Comment thread cpp/src/arrow/util/bit_run_reader.h Resolved
@HuaHuaY
HuaHuaY merged commit 7d57d68 into apache:main Dec 3, 2026
63 of 86 checks passed
@HuaHuaY
HuaHuaY deleted the large_bitmap branch December 3, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants