Skip to content
Merged
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
7 changes: 6 additions & 1 deletion cpp/src/gandiva/precompiled/string_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,12 @@ const char* repeat_utf8_int32(gdv_int64 context, const char* in, gdv_int32 in_le
*out_len = 0;
return "";
}
*out_len = repeat_number * in_len;
if (ARROW_PREDICT_FALSE(
arrow::internal::MultiplyWithOverflow(repeat_number, in_len, out_len))) {
gdv_fn_context_set_error_msg(context, "Would overflow maximum output size");
*out_len = 0;
return "";
}
char* ret = reinterpret_cast<char*>(gdv_fn_context_arena_malloc(context, *out_len));
if (ret == nullptr) {
gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string");
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/gandiva/precompiled/string_ops_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ TEST(TestStringOps, TestRepeat) {
EXPECT_EQ(std::string(out_str, out_len), "");
EXPECT_THAT(ctx.get_error(), ::testing::HasSubstr("Repeat number can't be negative"));
ctx.Reset();

out_str = repeat_utf8_int32(ctx_ptr, "aa", 2,
std::numeric_limits<int32_t>::max() / 2 + 1, &out_len);
EXPECT_EQ(std::string(out_str, out_len), "");
EXPECT_THAT(ctx.get_error(),
::testing::HasSubstr("Would overflow maximum output size"));
ctx.Reset();
}

TEST(TestStringOps, TestCastBoolToVarchar) {
Expand Down
Loading