You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/07/28 07:00:00 UTC
[doris] branch master updated: [fix](be): fix stack overflow in unhex function (#11204)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new b260a02215 [fix](be): fix stack overflow in unhex function (#11204)
b260a02215 is described below
commit b260a02215033e87c67b2ae09ba2ac9ff0a50aef
Author: spaces-x <we...@gmail.com>
AuthorDate: Thu Jul 28 14:59:54 2022 +0800
[fix](be): fix stack overflow in unhex function (#11204)
* [fix](be): fix stack overflow in unhex function
---
be/src/exprs/math_functions.cpp | 5 +++--
be/src/udf/udf.cpp | 4 ++--
be/src/udf/udf.h | 4 +++-
be/test/exprs/math_functions_test.cpp | 5 ++++-
4 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp
index cfda429db1..f21ebb2c62 100644
--- a/be/src/exprs/math_functions.cpp
+++ b/be/src/exprs/math_functions.cpp
@@ -381,7 +381,8 @@ StringVal MathFunctions::unhex(FunctionContext* ctx, const StringVal& s) {
}
int result_len = s.len / 2;
- char result[result_len];
+ StringVal result_string_val(ctx, result_len);
+ char* result = reinterpret_cast<char*>(result_string_val.ptr);
int res_index = 0;
int s_index = 0;
while (s_index < s.len) {
@@ -426,7 +427,7 @@ StringVal MathFunctions::unhex(FunctionContext* ctx, const StringVal& s) {
result[res_index] = c;
++res_index;
}
- return AnyValUtil::from_buffer_temp(ctx, result, result_len);
+ return result_string_val;
}
StringVal MathFunctions::conv_int(FunctionContext* ctx, const BigIntVal& num,
diff --git a/be/src/udf/udf.cpp b/be/src/udf/udf.cpp
index d73fc6d691..7f72be40df 100644
--- a/be/src/udf/udf.cpp
+++ b/be/src/udf/udf.cpp
@@ -209,11 +209,11 @@ FunctionContext* FunctionContextImpl::clone(MemPool* pool) {
namespace doris_udf {
static const int MAX_WARNINGS = 1000;
-FunctionContext* FunctionContext::create_test_context() {
+FunctionContext* FunctionContext::create_test_context(doris::MemPool* mem_pool = nullptr) {
FunctionContext* context = new FunctionContext();
context->impl()->_debug = true;
context->impl()->_state = nullptr;
- context->impl()->_pool = new doris::FreePool(nullptr);
+ context->impl()->_pool = new doris::FreePool(mem_pool);
return context;
}
diff --git a/be/src/udf/udf.h b/be/src/udf/udf.h
index 959deac8c4..c4e5583bfc 100644
--- a/be/src/udf/udf.h
+++ b/be/src/udf/udf.h
@@ -37,6 +37,7 @@ class BitmapValue;
class DecimalV2Value;
class DateTimeValue;
class CollectionValue;
+class MemPool;
} // namespace doris
namespace doris_udf {
@@ -255,7 +256,8 @@ public:
// Create a test FunctionContext object. The caller is responsible for calling delete
// on it. This context has additional debugging validation enabled.
- static FunctionContext* create_test_context();
+ // And the default value of mem_pool is nullprt.
+ static FunctionContext* create_test_context(doris::MemPool* mem_pool);
~FunctionContext();
diff --git a/be/test/exprs/math_functions_test.cpp b/be/test/exprs/math_functions_test.cpp
index 3cfdc4225a..e9231cbbe3 100644
--- a/be/test/exprs/math_functions_test.cpp
+++ b/be/test/exprs/math_functions_test.cpp
@@ -23,6 +23,7 @@
#include <string>
#include "runtime/large_int_value.h"
+#include "runtime/mem_pool.h"
#include "testutil/function_utils.h"
#include "udf/udf_internal.h"
@@ -217,7 +218,9 @@ TEST_F(MathFunctionsTest, hex_string) {
}
TEST_F(MathFunctionsTest, unhex) {
- doris_udf::FunctionContext* context = new doris_udf::FunctionContext();
+ MemPool mem_pool;
+ doris_udf::FunctionContext* context =
+ doris_udf::FunctionContext::create_test_context(&mem_pool);
EXPECT_EQ(StringVal::null(), MathFunctions::unhex(context, StringVal::null()));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org