This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 02716598d48 [Fix](sql function) memory overflow to the left of string
address when do_money_format has small negative value #36226 (#37870)
02716598d48 is described below
commit 02716598d48a83855519c88045b20d9185bf06f5
Author: zhiqiang <[email protected]>
AuthorDate: Tue Jul 16 15:04:42 2024 +0800
[Fix](sql function) memory overflow to the left of string address when
do_money_format has small negative value #36226 (#37870)
cherry pick from #36226
Co-authored-by: sparrow <[email protected]>
---
be/src/vec/functions/function_string.h | 5 ++++-
be/test/vec/function/function_math_test.cpp | 3 ++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/function_string.h
b/be/src/vec/functions/function_string.h
index 4096bcca6d3..df15bc600ec 100644
--- a/be/src/vec/functions/function_string.h
+++ b/be/src/vec/functions/function_string.h
@@ -3073,7 +3073,7 @@ static StringRef do_money_format(FunctionContext*
context, const string& value)
if (!is_positive) {
*result_data = '-';
}
- for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3, j =
j - 4) {
+ for (int i = value.size() - 4, j = result_len - 4; i >= 0; i = i - 3) {
*(result_data + j) = *(value.data() + i);
if (i - 1 < 0) {
break;
@@ -3085,6 +3085,9 @@ static StringRef do_money_format(FunctionContext*
context, const string& value)
*(result_data + j - 2) = *(value.data() + i - 2);
if (j - 3 > 1 || (j - 3 == 1 && is_positive)) {
*(result_data + j - 3) = ',';
+ j -= 4;
+ } else {
+ j -= 3;
}
}
memcpy(result_data + result_len - 3, value.data() + value.size() - 3, 3);
diff --git a/be/test/vec/function/function_math_test.cpp
b/be/test/vec/function/function_math_test.cpp
index c93c6ca324f..00d0770935b 100644
--- a/be/test/vec/function/function_math_test.cpp
+++ b/be/test/vec/function/function_math_test.cpp
@@ -511,7 +511,8 @@ TEST(MathFunctionTest, money_format_test) {
InputTypeSet input_types = {TypeIndex::Float64};
DataSet data_set = {{{Null()}, Null()},
{{DOUBLE(17014116.67)}, VARCHAR("17,014,116.67")},
- {{DOUBLE(-17014116.67)},
VARCHAR("-17,014,116.67")}};
+ {{DOUBLE(-17014116.67)},
VARCHAR("-17,014,116.67")},
+ {{DOUBLE(-123.45)}, VARCHAR("-123.45")}};
static_cast<void>(check_function<DataTypeString, true>(func_name,
input_types, data_set));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]