bkietz commented on code in PR #626:
URL: https://github.com/apache/arrow-nanoarrow/pull/626#discussion_r1767643653


##########
src/nanoarrow/common/array.c:
##########
@@ -1249,13 +1249,21 @@ static int ArrowArrayViewValidateFull(struct 
ArrowArrayView* array_view,
                                       struct ArrowError* error) {
   for (int i = 0; i < NANOARROW_MAX_FIXED_BUFFERS; i++) {
     switch (array_view->layout.buffer_type[i]) {
+      // Only validate the portion of the buffer that is strictly required,
+      // which includes not validating the offset buffer of a zero-length 
array.
       case NANOARROW_BUFFER_TYPE_DATA_OFFSET:
-        if (array_view->layout.element_size_bits[i] == 32) {
-          NANOARROW_RETURN_NOT_OK(
-              ArrowAssertIncreasingInt32(array_view->buffer_views[i], error));
-        } else {
-          NANOARROW_RETURN_NOT_OK(
-              ArrowAssertIncreasingInt64(array_view->buffer_views[i], error));
+        if (array_view->layout.element_size_bits[i] == 32 && 
array_view->length > 0) {
+          struct ArrowBufferView offset_minimal;
+          offset_minimal.data.as_int32 =
+              array_view->buffer_views[i].data.as_int32 + array_view->offset;
+          offset_minimal.size_bytes = (array_view->length + 1) * 
sizeof(int32_t);
+          NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt32(offset_minimal, 
error));
+        } else if (array_view->length > 0) {
+          struct ArrowBufferView offset_minimal;
+          offset_minimal.data.as_int64 =
+              array_view->buffer_views[i].data.as_int64 + array_view->offset;
+          offset_minimal.size_bytes = (array_view->length + 1) * 
sizeof(int64_t);
+          NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt64(offset_minimal, 
error));
         }

Review Comment:
   Nit:
   ```suggestion
           if (array_view->length == 0) {
             continue;
           }
           if (array_view->layout.element_size_bits[i] == 32) {
             struct ArrowBufferView offset_minimal;
             offset_minimal.data.as_int32 =
                 array_view->buffer_views[i].data.as_int32 + array_view->offset;
             offset_minimal.size_bytes = (array_view->length + 1) * 
sizeof(int32_t);
             NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt32(offset_minimal, 
error));
           } else {
             struct ArrowBufferView offset_minimal;
             offset_minimal.data.as_int64 =
                 array_view->buffer_views[i].data.as_int64 + array_view->offset;
             offset_minimal.size_bytes = (array_view->length + 1) * 
sizeof(int64_t);
             NANOARROW_RETURN_NOT_OK(ArrowAssertIncreasingInt64(offset_minimal, 
error));
           }
   ```



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