Arawoof06 commented on code in PR #50441:
URL: https://github.com/apache/arrow/pull/50441#discussion_r3585101842


##########
cpp/src/gandiva/precompiled/time_test.cc:
##########
@@ -59,6 +63,56 @@ TEST(TestTime, TestCastDate) {
   EXPECT_EQ(castDATE_date32(1), 86400000);
 }
 
+TEST(TestTime, TestCastDateInvalidUnterminated) {
+  ExecutionContext context;
+  int64_t context_ptr = reinterpret_cast<int64_t>(&context);
+
+  // The invalid-value error message is built from the raw input pointer. Hold
+  // the input in an exactly-sized heap buffer with no trailing NUL so that
+  // formatting the error must respect `length` instead of scanning for a NUL;
+  // any over-read past the buffer trips AddressSanitizer.
+  const char bytes[] = {'1', '9', '7', '2', '2', '2', '2', '2', '2', '2'};
+  const auto length = static_cast<int32_t>(sizeof(bytes));
+  std::unique_ptr<char[]> input(new char[length]);
+  std::memcpy(input.get(), bytes, length);
+
+  EXPECT_EQ(castDATE_utf8(context_ptr, input.get(), length), 0);

Review Comment:
   Good call, that's cleaner. Switched all three to a std::string with a 
trailing sentinel and pass length - 1, so the over-read shows up as the 
sentinel leaking into the message even without ASAN. Used 197201234X for the 
date one per your suggestion.



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