Repository navigation
fix(arrow-array): return an error instead of wrapping on MapBuilder offset overflow - #12052
Merged
Merged
Conversation
…ffset overflow MapBuilder::append and append_nulls cast the entry count to i32 with 'as', which wraps to a negative offset once the builders hold more than i32::MAX entries, silently producing an invalid MapArray. Convert with i32::try_from before mutating any state and return an InvalidArgumentError on overflow. Closes apache#12031
Jefffrey
approved these changes
Nov 4, 2026
Contributor
|
thanks @llxgdtop |
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.
Which issue does this PR close?
as#12031Rationale for this change
When the key and value builders hold more than
i32::MAXentries, theas i32cast of the entry count wraps to a negative number.appendstill returns
Ok(()), so the caller has no way to notice and ends upwith a
MapArraywhose offsets are invalid.What changes are included in this PR?
next_offsethelper that converts the entry count withi32::try_fromand returns anInvalidArgumentErroron overflow.appendandappend_nulls. The check runs before any stateis mutated, so a rejected call leaves the builder unchanged.
Are these changes tested?
Yes. A new unit test uses a mock
ArrayBuilderthat reports a length ofi32::MAX + 1without allocating, and asserts that bothappendandappend_nullsreturn an error and leave the builder untouched. The testfails on
mainand passes with this change.Are there any significant user-facing changes?
No. The method signatures already returned
Result; the only behaviouraldifference is that an overflow now surfaces as an error instead of
silently corrupting the array.