Skip to content

feat(arrow-buffer): add OutOfBoundsError and fallible Buffer slicing - #10737

Draft
emilk wants to merge 1 commit into
apache:mainfrom
emilk:emilk/out-of-bounds-error
Draft

feat(arrow-buffer): add OutOfBoundsError and fallible Buffer slicing#10737
emilk wants to merge 1 commit into
apache:mainfrom
emilk:emilk/out-of-bounds-error

Conversation

@emilk

@emilk emilk commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Buffer::slice, Buffer::advance and Buffer::slice_with_length panic when asked for a range the buffer does not hold, and there is no way to ask without risking the panic. They are also the reason ScalarBuffer::new cannot get a try_new yet: two of its four panic causes come from these functions.

arrow-buffer does not depend on arrow-schema, so it has no ArrowError. It uses one small error type per concern instead (MutableBufferError, ParseI256Error), so this adds one more in that style.

What changes are included in this PR?

OutOfBoundsError (Copy, no allocation) and a try_ variant for each of the three:

  • Buffer::try_slice
  • Buffer::try_advance, which leaves the buffer unchanged when it fails
  • Buffer::try_slice_with_length

The panicking versions delegate to the fallible ones and keep their existing panic messages verbatim, since arrow-array and others assert on them.

Buffer::bit_slice is left alone: its panic comes from two different paths and deserves its own change.

Note this adds arrow-buffer/src/error.rs, the same file as #10736. Whichever lands first, I will rebase the other.

Are these changes tested?

Yes, new tests for each error path, including offset + length overflowing usize. The existing should_panic tests are untouched, which is what pins the panic messages.

Are there any user-facing changes?

New public API only, no breaking changes.

`Buffer::slice`, `advance` and `slice_with_length` panic when asked for a
range they do not hold. Add `OutOfBoundsError` and a `try_` variant for each:

* `Buffer::try_slice`
* `Buffer::try_advance` (leaves the buffer unchanged on failure)
* `Buffer::try_slice_with_length`

The panicking versions delegate to the fallible ones and keep their existing
panic messages, which several crates assert on in tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added arrow Changes to the arrow crate arrow-buffer labels Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-buffer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant