Kikkon commented on code in PR #5664:
URL: https://github.com/apache/arrow-rs/pull/5664#discussion_r1581850201


##########
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:
   Why do we need to check if both the offset and size are i64::max here? Are 
we concerned about exceeding the maximum limit of usize? I don't think either 
of them should exceed the maximum value of usize, right?



-- 
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]

Reply via email to