Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/src/gandiva/precompiled/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void set_error_for_date(gdv_int32 length, const char* input, const char* msg,
int64_t execution_context) {
int size = length + static_cast<int>(strlen(msg)) + 1;
char* error = reinterpret_cast<char*>(malloc(size));
snprintf(error, size, "%s%s", msg, input);
snprintf(error, size, "%s%.*s", msg, length, input);
gdv_fn_context_set_error_msg(execution_context, error);
free(error);
}
Expand Down
22 changes: 22 additions & 0 deletions cpp/src/gandiva/precompiled/time_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <cstring>
#include <memory>
#include <string>

#include "arrow/util/logging_internal.h"
#include "gandiva/execution_context.h"
#include "gandiva/precompiled/testing.h"
Expand Down Expand Up @@ -59,6 +63,24 @@ 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);
EXPECT_EQ(context.get_error(), "Not a valid date value 1972222222");
context.Reset();
}

TEST(TestTime, TestCastTimestamp) {
ExecutionContext context;
int64_t context_ptr = reinterpret_cast<int64_t>(&context);
Expand Down
Loading