Copilot commented on code in PR #49712:
URL: https://github.com/apache/arrow/pull/49712#discussion_r3459869740


##########
r/src/array_to_vector.cpp:
##########
@@ -497,6 +503,44 @@ class Converter_Binary : public Converter {
   virtual bool Parallel() const { return false; }
 };
 
+class Converter_BinaryView : public Converter {
+ public:
+  explicit Converter_BinaryView(const std::shared_ptr<ChunkedArray>& 
chunked_array)
+      : Converter(chunked_array) {}
+
+  SEXP Allocate(R_xlen_t n) const {
+    SEXP res = PROTECT(Rf_allocVector(VECSXP, n));
+    Rf_classgets(res, data::classes_arrow_binary);
+    UNPROTECT(1);
+    return res;
+  }
+
+  Status Ingest_all_nulls(SEXP data, R_xlen_t start, R_xlen_t n) const {
+    return Status::OK();
+  }
+
+  Status Ingest_some_nulls(SEXP data, const std::shared_ptr<arrow::Array>& 
array,
+                           R_xlen_t start, R_xlen_t n, size_t chunk_index) 
const {
+    const BinaryViewArray* binary_array =
+        checked_cast<const BinaryViewArray*>(array.get());
+
+    auto ingest_one = [&](R_xlen_t i) {
+      auto value = binary_array->GetView(i);
+      SEXP raw = PROTECT(Rf_allocVector(RAWSXP, value.size()));
+      std::copy(value.data(), value.data() + value.size(), RAW(raw));
+
+      SET_VECTOR_ELT(data, i + start, raw);
+      UNPROTECT(1);
+
+      return Status::OK();
+    };

Review Comment:
   `Converter_BinaryView::Ingest_some_nulls()` allocates a raw vector using 
`value.size()` without checking it fits in R’s vector length limits. For large 
BinaryView values this can overflow the `Rf_allocVector()` length argument and 
lead to allocation errors or memory corruption; `Converter_Binary` guards this 
with an `R_XLEN_T_MAX` check.



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