You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/07 18:53:30 UTC

[GitHub] [arrow-rs] viirya commented on a diff in pull request #1816: Fix Decimal and List ArrayData Validation (#1813) (#1814)

viirya commented on code in PR #1816:
URL: https://github.com/apache/arrow-rs/pull/1816#discussion_r891600614


##########
arrow/src/array/data.rs:
##########
@@ -738,40 +738,47 @@ impl ArrayData {
     /// entries.
     ///
     /// For an empty array, the `buffer` can also be empty.
-    fn typed_offsets<'a, T: ArrowNativeType + num::Num + std::fmt::Display>(
-        &'a self,
-        buffer: &'a Buffer,
-    ) -> Result<&'a [T]> {
+    fn typed_offsets<T: ArrowNativeType + num::Num>(&self) -> Result<&[T]> {
         // An empty list-like array can have 0 offsets
-        if buffer.is_empty() && self.len == 0 {
+        if self.len == 0 && self.buffers[0].is_empty() {
             return Ok(&[]);
         }
 
-        // Validate that there are the correct number of offsets for this array's length
-        let required_offsets = self.len + self.offset + 1;
+        self.typed_buffer(0, self.len + 1)
+    }
+
+    /// Returns a reference to the data in `buffer` as a typed slice after validating
+    fn typed_buffer<T: ArrowNativeType + num::Num>(
+        &self,
+        idx: usize,
+        len: usize,
+    ) -> Result<&[T]> {
+        let buffer = &self.buffers[idx];
+
+        let required_len = (len + self.offset) * std::mem::size_of::<T>();
 
-        if (buffer.len() / std::mem::size_of::<T>()) < required_offsets {
+        if buffer.len() < required_len {

Review Comment:
   Hmm, shouldn't it be
   
   ```rust
   let required_len = len * std::mem::size_of::<T>();
   if buffer.len() < required_len {
     ...
   }
   ```
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org