Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed: (offset + length) <= self.len()")]
#[should_panic(expected = "assertion failed: end <= self.len()")]
// Different error messages, so skip for now
// https://github.com/apache/arrow-rs/issues/1545
#[cfg(not(feature = "force_validate"))]
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ mod tests {
}

#[test]
#[should_panic(expected = "assertion failed: (offset + length) <= self.len()")]
#[should_panic(expected = "assertion failed: end <= self.len()")]
fn test_struct_array_from_data_with_offset_and_length_error() {
let int_arr = Int32Array::from(vec![1, 2, 3, 4, 5]);
let int_field = Field::new("x", DataType::Int32, false);
Expand Down
20 changes: 18 additions & 2 deletions arrow-data/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,12 @@ impl ArrayData {
///
/// # Panics
///
/// Panics if `offset + length > self.len()`.
/// Panics if `offset + length` overflows or is greater than `self.len()`.
pub fn slice(&self, offset: usize, length: usize) -> ArrayData {
assert!((offset + length) <= self.len());
let end = offset
.checked_add(length)
.expect("offset + length overflow");
assert!(end <= self.len());

if let DataType::Struct(_) = self.data_type() {
// Slice into children
Expand Down Expand Up @@ -2258,6 +2261,19 @@ mod tests {
assert_eq!(data.null_count() - 1, new_data.null_count());
}

#[test]
#[should_panic(expected = "offset + length overflow")]
fn test_slice_panics_on_offset_length_overflow() {
let data = ArrayData::builder(DataType::Int32)
.len(4)
.add_buffer(make_i32_buffer(4))
.build()
.unwrap();
let sliced = data.slice(1, 3);

sliced.slice(1, usize::MAX);
}

#[test]
fn test_equality() {
let int_data = ArrayData::builder(DataType::Int32)
Expand Down
Loading