Skip to content
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
19 changes: 17 additions & 2 deletions arrow-row/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,14 +1020,20 @@ impl Rows {

/// Returns the row at index `row`
pub fn row(&self, row: usize) -> Row<'_> {
assert!(row + 1 < self.offsets.len());
self.checked_row_end(row);
unsafe { self.row_unchecked(row) }
}

fn checked_row_end(&self, row: usize) -> usize {
row.checked_add(1)
.filter(|end| *end < self.offsets.len())
.expect("row index out of bounds")
}

/// Returns the row at `index` without bounds checking
///
/// # Safety
/// Caller must ensure that `index` is less than the number of offsets (#rows + 1)
/// Caller must ensure that `index + 1` is less than the number of offsets (#rows + 1)
pub unsafe fn row_unchecked(&self, index: usize) -> Row<'_> {
let end = unsafe { self.offsets.get_unchecked(index + 1) };
let start = unsafe { self.offsets.get_unchecked(index) };
Expand Down Expand Up @@ -3588,4 +3594,13 @@ mod tests {
assert_eq!(unchecked_values_len, 13);
assert!(checked_values_len > unchecked_values_len);
}

#[test]
#[should_panic(expected = "row index out of bounds")]
fn row_should_panic_on_overflowing_index() {
let rows = RowConverter::new(vec![SortField::new(DataType::Int32)])
.unwrap()
.empty_rows(0, 0);
rows.row(usize::MAX);
}
}
Loading