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


##########
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:
   Can we simplify this? I think that this will include `X` in the error 
message without this fix.
   
   ```suggestion
     const std::string input = "1972222222X";
     EXPECT_EQ(castDATE_utf8(context_ptr, input.get(), input.length() - 1), 0);
   ```
   
   BTW, can we use different numbers instead of multiple `2` something like 
`197201234X`.



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