alamb commented on code in PR #9817:
URL: https://github.com/apache/arrow-rs/pull/9817#discussion_r3148914720
##########
arrow-row/src/lib.rs:
##########
@@ -1255,14 +1255,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")
Review Comment:
In rust `assert!` is not optimized away in release builds (only
`debug_assert!` is)
The change here also also checks for overflow when doing row + 1 (using
checked_add). Without that, if you pass in `usize::MAX` it will wrap around to
0, which I think will pass the assert and not trigger the panic
I do think trying to access memory at offset `uisze::MAX` will then most
likely then cause a SIGSEGV, but it seemed better to check the corner case
anyway
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]