Skip to content

fix: disallow sliced buffer regardless of sliced direction in Buffer::into_mutable and add Buffer::is_sliced and Buffer::into_mutable_unsliced#10118

Open
rluvaton wants to merge 5 commits into
apache:mainfrom
rluvaton:disallow-sliced-into_mutable
Open

fix: disallow sliced buffer regardless of sliced direction in Buffer::into_mutable and add Buffer::is_sliced and Buffer::into_mutable_unsliced#10118
rluvaton wants to merge 5 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

change for Buffer::into_mutable will lead to panic in case of owned sliced buffer when offset is greater than 0
and will lead to confusing behavior (roundtrip will have different length) when called with sliced buffer when offset is 0 but length is less than underlying data length

the addition of the Buffer::into_mutable_unsliced is to allow getting the MutableBuffer regardless of the sliced, and the user will be aware of that the returned MutableBuffer can have different length and more data

the addition of Buffer::is_sliced so the user can know if the buffer is sliced and act accordingly

What changes are included in this PR?

  1. updating Buffer::into_mutable to disallow converting to mutable in case of sliced buffer regardless of offset
  2. Added Buffer::into_mutable_unsliced to allow the user getting the entire unsliced data in MutableBuffer and the user is aware of the implications
  3. added Buffer:is_sliced

Are these changes tested?

yes

Are there any user-facing changes?

yes, new functions and 1 breaking change - call to Buffer::into_mutable with buffer that is sliced from 0 to not the end of the underlying data will now return Err

fn main() {
  let bytes = vec![0_u8; 8];

  let buffer = Buffer::from(bytes.clone());
  let sliced = buffer.slice_with_length(4, 4);
  drop(buffer);
  sliced.into_mutable();  // <-- This will now return error instead of panic

  let buffer = Buffer::from(bytes.clone());
  let sliced = buffer.slice_with_length(0, 4);
  drop(buffer);
  sliced.into_mutable(); // <-- This will now return error instead of returning MutableBuffer with data outside slice 
}

rluvaton added a commit to rluvaton/arrow-rs that referenced this pull request Jun 11, 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

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

1 participant