Repository navigation
GH-55945: [C++] Clamp partial-byte lengths before narrowing in SetBitRunReader - #55946
Merged
Merged
Conversation
wgtmac
approved these changes
Dec 3, 2026
Contributor
There was a problem hiding this comment.
🟡 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_tbefore narrowing toint32_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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Rationale for this change
SetBitRunReadernarrows the slice length toint32_tbefore 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_tbefore 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:
Reviewed before submission by: