You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "paleolimbot (via GitHub)" <gi...@apache.org> on 2024/09/19 18:59:54 UTC

[PR] fix: Only validate portions of offset buffers strictly required [arrow-nanoarrow]

paleolimbot opened a new pull request, #626:
URL: https://github.com/apache/arrow-nanoarrow/pull/626

   (no comment)


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


Re: [PR] fix: Only validate portions of offset buffers strictly required [arrow-nanoarrow]

Posted by "bkietz (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] fix: Improve validation of offset buffers for sliced arrays [arrow-nanoarrow]

Posted by "bkietz (via GitHub)" <gi...@apache.org>.
bkietz merged PR #626:
URL: https://github.com/apache/arrow-nanoarrow/pull/626


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