Skip to content

MapBuilder: check offsets instead of casting via as #12031

Closed

Description

@Jefffrey

Describe the bug

pub fn append(&mut self, is_valid: bool) -> Result<(), ArrowError> {
self.validate_equal_lengths()?;
self.offsets_builder.push(self.key_builder.len() as i32);
self.null_buffer_builder.append(is_valid);
Ok(())
}

pub fn append_nulls(&mut self, n: usize) -> Result<(), ArrowError> {
self.validate_equal_lengths()?;
let offset = self.key_builder.len() as i32;
self.offsets_builder.extend(std::iter::repeat_n(offset, n));
self.null_buffer_builder.append_n_nulls(n);
Ok(())
}

In these methods we append offset using as i32 cast, which in extreme cases can wrap. We should be checking this to error if it overflows, otherwise it can create an invalid map array (wraps to negative, offsets no longer valid)

To Reproduce

No response

Expected behavior

No response

Additional context

Identified by Dr Charles Grellois

Activity

  1. added theissue type on Nov 2, 2026
  2. added
    bug
    on Nov 2, 2026
  3. llxgdtop commented on Nov 3, 2026

    @llxgdtop
    Contributor

    take

  4. added 2 commits that reference this issue on Nov 3, 2026
    f2cc894
    3a012c9
  5. added a commit that references this issue on Nov 4, 2026
    53ef3bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions