dmitry-chirkov-dremio commented on code in PR #50947:
URL: https://github.com/apache/arrow/pull/50947#discussion_r4289367590


##########
cpp/src/gandiva/gdv_string_function_stubs.cc:
##########
@@ -289,6 +289,14 @@ const char* gdv_fn_lower_utf8(int64_t context, const char* 
data, int32_t data_le
     }
 
     // Control reaches here when we encounter a multibyte character
+    // Ensure the multibyte sequence fits within the buffer to avoid
+    // reading past data_len (truncated trailing multibyte sequence).
+    if (char_len > data_len - i) {
+      gdv_fn_set_error_for_invalid_utf8(context, data[i]);

Review Comment:
   Could we also add `NativeFunction::kCanReturnErrors` to the `lower` and 
`upper` registrations in `function_registry_string.cc`, following the same 
NULL-handling fix as https://github.com/apache/arrow/pull/49035 for 
`binary_string`? `initcap` already has the flag.
   
   Without it, Gandiva invokes these functions even on NULL inputs, so the new 
truncation checks can fail a batch on bytes belonging to a NULL slot.
   
   Please add Projector-level regressions for both functions, following the 
setup in 
[`TestUtf8.TestInternalAllocs`](https://github.com/apache/arrow/blob/dd47db3afcd06f1b2737bc31250d99a2ee113ec9/cpp/src/gandiva/tests/utf8_test.cc#L360-L402).
 Construct that NULL input and assert evaluation succeeds and the output 
remains NULL. Direct stub tests bypass the generated validity handling and 
cannot catch this.



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