tustvold commented on code in PR #5664:
URL: https://github.com/apache/arrow-rs/pull/5664#discussion_r1580874207
##########
arrow-data/src/data.rs:
##########
@@ -929,6 +929,43 @@ impl ArrayData {
Ok(())
}
+ /// Does a cheap sanity check that the `self.len` values in `buffer` are
valid
+ /// offsets and sizes (of type T) into some other buffer of
`values_length` bytes long
+ fn validate_offsets_and_sizes<T: ArrowNativeType + num::Num +
std::fmt::Display>(
+ &self,
+ values_length: usize,
+ ) -> Result<(), ArrowError> {
+ let offsets: &[T] = self.typed_buffer(0, self.len)?;
+ let sizes: &[T] = self.typed_buffer(1, self.len)?;
+ for i in 0..values_length {
+ let size = sizes[i].to_usize().ok_or_else(|| {
+ ArrowError::InvalidArgumentError(format!(
+ "Error converting size[{}] ({}) to usize for {}",
+ i, sizes[i], self.data_type
+ ))
+ })?;
+ let offset = offsets[i].to_usize().ok_or_else(|| {
+ ArrowError::InvalidArgumentError(format!(
+ "Error converting offset[{}] ({}) to usize for {}",
+ i, offsets[i], self.data_type
+ ))
+ })?;
+ if offset > values_length {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Size {} at index {} is offset {} is out of bounds for {}",
+ size, i, offset, self.data_type
+ )));
+ }
+ if size + offset > values_length {
Review Comment:
I think this needs to be checked addition to handle if size and offset were
both `i64::MAX`, perhaps we could get a test of this?
--
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]