Kikkon commented on code in PR #5664:
URL: https://github.com/apache/arrow-rs/pull/5664#discussion_r1579350670
##########
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 > values_length - offset {
+ return Err(ArrowError::InvalidArgumentError(format!(
+ "Size {} at index {} is larger than the remaining values
for {}",
+ size, i, self.data_type
+ )));
+ }
Review Comment:
Since the offset is already greater than 0, there is no boundary check for 0
here. I have adjusted the order for easier understanding.
--
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]