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


##########
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:
   This logic does not appear to be correct
   
   From https://arrow.apache.org/docs/format/Columnar.html#listview-layout the 
variants this should be validating are
   
   ```
   0 <= offsets[i] <= length of the child array
   0 <= offsets[i] + size[i] <= length of the child array
   ```



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