Skip to content

Segfault in ByteGroupValueBuilder #15968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ where
offsets: Vec<O>,
/// Nulls
nulls: MaybeNullBufferBuilder,
/// The maximum size of the buffer for `0`
max_buffer_size: usize,
}

impl<O> ByteGroupValueBuilder<O>
Expand All @@ -62,6 +64,11 @@ where
buffer: BufferBuilder::new(INITIAL_BUFFER_CAPACITY),
offsets: vec![O::default()],
nulls: MaybeNullBufferBuilder::new(),
max_buffer_size: if O::IS_LARGE {
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find any other way to get the max value of the offset size, which is weird. Maybe it would be a nice addition to arrow-rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

i64::MAX as usize
} else {
i32::MAX as usize
},
}
}

Expand Down Expand Up @@ -187,6 +194,13 @@ where
{
let value: &[u8] = array.value(row).as_ref();
self.buffer.append_slice(value);

assert!(
self.buffer.len() <= self.max_buffer_size,
"offset overflow, buffer size > {}",
self.max_buffer_size
);

self.offsets.push(O::usize_as(self.buffer.len()));
}

Expand Down Expand Up @@ -318,6 +332,7 @@ where
mut buffer,
offsets,
nulls,
..
} = *self;

let null_buffer = nulls.build();
Expand Down Expand Up @@ -410,6 +425,24 @@ mod tests {

use super::GroupColumn;

#[test]
#[should_panic]
fn test_byte_group_value_builder_overflow() {
let mut builder = ByteGroupValueBuilder::<i32>::new(OutputType::Utf8);

let large_string = "a".repeat(1024 * 1024);

let array =
Arc::new(StringArray::from(vec![Some(large_string.as_str())])) as ArrayRef;

// Append items until our buffer length is 1 + i32::MAX as usize
for _ in 0..2048 {
builder.append_val(&array, 0);
}

assert_eq!(builder.value(2047), large_string.as_bytes());
}

#[test]
fn test_byte_take_n() {
let mut builder = ByteGroupValueBuilder::<i32>::new(OutputType::Utf8);
Expand Down