Skip to content

fix: Buffer::into_mutable return error instead of panic for converting owned sliced when not start at 0 and fix returned Mutable length#10118

Merged
alamb merged 8 commits into
apache:mainfrom
rluvaton:disallow-sliced-into_mutable
Jun 24, 2026
Merged

fix: Buffer::into_mutable return error instead of panic for converting owned sliced when not start at 0 and fix returned Mutable length#10118
alamb merged 8 commits into
apache:mainfrom
rluvaton:disallow-sliced-into_mutable

Conversation

@rluvaton

@rluvaton rluvaton commented Jun 11, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

This include 2 fixes:

  1. Calling Buffer::into_mutable on owned sliced that Buffer::ptr_offset() > 0 panicked before, now returning error
  2. Calling Buffer::into_mutable on owned slice that Buffer::ptr_offset() == 0 returned MutableBuffer with length greater than the original buffer length

What changes are included in this PR?

  1. Updating Buffer::into_mutable to return error when ptr_offset > 0
  2. Set the returned MutableBuffer length to the original buffer length so length is the same

Are these changes tested?

yes

Are there any user-facing changes?

not really, except error instead of panic and correct mutable length

rluvaton added a commit to rluvaton/arrow-rs that referenced this pull request Jun 11, 2026

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rluvaton

I agree we should avoid panics and intead return error. However, this PR seems to be trying to allow some sort of mutable buffer conversion even when the buffer is sliced.

I am not sure about the usecase for this API change -- it seems like the API would get more complicated with this PR.

If you want to allow reusing an allocation from a sliced buffer, how about something like

let unsliced_buffer = buffer.unslice(); <-- new API, clear the offset
let mutable =  unsliced_buffer.int_mutable();
..

Then we could add a doc example showing how to unslice a buffer and how to reuse a sliced buffer

Comment thread arrow-buffer/src/buffer/immutable.rs
Comment thread arrow-buffer/src/buffer/immutable.rs
@rluvaton

Copy link
Copy Markdown
Member Author

I like the idea of unslice will split to 2 PRs

@alamb alamb marked this pull request as draft June 18, 2026 19:54
@alamb

alamb commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Marking as draft as I think this PR is no longer waiting on feedback and I am trying to make it easier to find PRs in need of review. Please mark it as ready for review when it is ready for another look

@rluvaton rluvaton changed the title fix: disallow sliced buffer regardless of sliced direction in Buffer::into_mutable and add Buffer::is_sliced and Buffer::into_mutable_unsliced fix: Buffer::into_mutable return error instead of panic for converting owned sliced when not start at 0 and fix returned Mutable length Jun 23, 2026
@rluvaton rluvaton marked this pull request as ready for review June 23, 2026 08:38
@rluvaton

Copy link
Copy Markdown
Member Author

@alamb I fixed the code, it fix 2 bugs, the panic and different length for sliced

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @rluvaton

Comment thread arrow-buffer/src/buffer/immutable.rs Outdated
@rluvaton

Copy link
Copy Markdown
Member Author

@Jefffrey / @alamb can you please merge this?

@alamb alamb merged commit 4e55832 into apache:main Jun 24, 2026
30 checks passed
@alamb

alamb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

✅ thank you @rluvaton

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buffer::into_mutable is not consistent regarding sliced data and can lead to panics

3 participants