You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2022/07/25 02:31:31 UTC

[arrow] branch master updated: ARROW-17191: [C++][FlightRPC] Handle inlined slices after concatenation (#13696)

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new ef6049a2ee ARROW-17191: [C++][FlightRPC] Handle inlined slices after concatenation (#13696)
ef6049a2ee is described below

commit ef6049a2ee5673d0944a0b4f70ff9c70e0419a22
Author: David Li <li...@gmail.com>
AuthorDate: Sun Jul 24 22:31:25 2022 -0400

    ARROW-17191: [C++][FlightRPC] Handle inlined slices after concatenation (#13696)
    
    See the JIRA for details, but essentially: data was getting corrupted since allocating a new `shared_ptr` control block was overwriting the data in a `GrpcBuffer`. This happened because the data was inlined into the structure, which we weren't properly accounting for. Instead, copy the data into a new buffer in these cases.
    
    I'm not sure why creating a new `shared_ptr` was overlapping an existing allocation, however.
    
    Authored-by: David Li <li...@gmail.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 .../arrow/flight/transport/grpc/serialization_internal.cc   | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/cpp/src/arrow/flight/transport/grpc/serialization_internal.cc b/cpp/src/arrow/flight/transport/grpc/serialization_internal.cc
index e51da615bb..8514ca361d 100644
--- a/cpp/src/arrow/flight/transport/grpc/serialization_internal.cc
+++ b/cpp/src/arrow/flight/transport/grpc/serialization_internal.cc
@@ -134,10 +134,17 @@ class GrpcBuffer : public MutableBuffer {
         return Status::IOError("Internal gRPC error reading from ByteBuffer");
       }
       grpc_slice slice = grpc_byte_buffer_reader_readall(&reader);
+      if (slice.refcount) {
+        // Steal the slice reference
+        *out = std::make_shared<GrpcBuffer>(slice, false);
+      } else {
+        // grpc_byte_buffer_reader_readall can give us an inlined slice,
+        // copy the data as above
+        const uint8_t length = slice.data.inlined.length;
+        ARROW_ASSIGN_OR_RAISE(*out, arrow::AllocateBuffer(length));
+        std::memcpy((*out)->mutable_data(), slice.data.inlined.bytes, length);
+      }
       grpc_byte_buffer_reader_destroy(&reader);
-
-      // Steal the slice reference
-      *out = std::make_shared<GrpcBuffer>(slice, false);
     }
 
     return Status::OK();