Skip to content

fix(arrow-array): return an error instead of wrapping on MapBuilder offset overflow - #12052

Merged
Jefffrey merged 1 commit into
apache:mainfrom
llxgdtop:fix-map-builder-offset-overflow
Nov 4, 2026
Merged

Jefffrey merged 1 commit into
apache:mainfrom
llxgdtop:fix-map-builder-offset-overflow

Conversation

@llxgdtop

@llxgdtop llxgdtop commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

When the key and value builders hold more than i32::MAX entries, the
as i32 cast of the entry count wraps to a negative number. append
still returns Ok(()), so the caller has no way to notice and ends up
with a MapArray whose offsets are invalid.

What changes are included in this PR?

  • Add a private next_offset helper that converts the entry count with
    i32::try_from and returns an InvalidArgumentError on overflow.
  • Use it in append and append_nulls. The check runs before any state
    is mutated, so a rejected call leaves the builder unchanged.
  • Document the new error condition on both methods.

Are these changes tested?

Yes. A new unit test uses a mock ArrayBuilder that reports a length of
i32::MAX + 1 without allocating, and asserts that both append and
append_nulls return an error and leave the builder untouched. The test
fails on main and passes with this change.

Are there any significant user-facing changes?

No. The method signatures already returned Result; the only behavioural
difference is that an overflow now surfaces as an error instead of
silently corrupting the array.


…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
@github-actions github-actions Bot added arrow-core Core crates related to representing arrow data bug Squash those bugs labels Nov 3, 2026
@Jefffrey
Jefffrey added this pull request to the merge queue Nov 4, 2026
@Jefffrey

Jefffrey commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

thanks @llxgdtop

Merged via the queue into apache:main with commit 53ef3bf Nov 4, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow-core Core crates related to representing arrow data bug Squash those bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MapBuilder: check offsets instead of casting via as

2 participants