This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 10a39ccc507 [fix](function) Correct Base64 buffer sizing and invalid
input handling (#65958)
10a39ccc507 is described below
commit 10a39ccc507d648eb9f4e6336dd2204357124823
Author: Mryange <[email protected]>
AuthorDate: Wed Jul 29 08:43:37 2026 +0800
[fix](function) Correct Base64 buffer sizing and invalid input handling
(#65958)
### What problem does this PR solve?
4.1 fix https://github.com/apache/doris/pull/65141
---
be/src/vec/functions/function_string.cpp | 9 +++++++--
be/test/vec/function/function_string_test.cpp | 17 +++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/be/src/vec/functions/function_string.cpp
b/be/src/vec/functions/function_string.cpp
index 942c30661e9..af7cf3a306c 100644
--- a/be/src/vec/functions/function_string.cpp
+++ b/be/src/vec/functions/function_string.cpp
@@ -1099,7 +1099,7 @@ struct ToBase64Impl {
continue;
}
- auto cipher_len = srclen / 2;
+ auto cipher_len = (srclen + 2) / 3 * 4;
char* dst = nullptr;
if (cipher_len <= stack_buf.size()) {
dst = stack_buf.data();
@@ -1142,7 +1142,12 @@ struct FromBase64Impl {
continue;
}
- auto cipher_len = srclen / 2;
+ if (UNLIKELY(srclen % 4 != 0)) {
+ StringOP::push_null_string(i, dst_data, dst_offsets, null_map);
+ continue;
+ }
+
+ auto cipher_len = srclen / 4 * 3;
char* dst = nullptr;
if (cipher_len <= stack_buf.size()) {
dst = stack_buf.data();
diff --git a/be/test/vec/function/function_string_test.cpp
b/be/test/vec/function/function_string_test.cpp
index 7d51269f9b4..a0a4bb16829 100644
--- a/be/test/vec/function/function_string_test.cpp
+++ b/be/test/vec/function/function_string_test.cpp
@@ -1488,6 +1488,12 @@ TEST(function_string_test, function_null_or_empty_test) {
TEST(function_string_test, function_to_base64_test) {
std::string func_name = "to_base64";
InputTypeSet input_types = {PrimitiveType::TYPE_VARCHAR};
+ std::string large_input(60000, 'a');
+ std::string large_output;
+ large_output.reserve(80000);
+ for (int i = 0; i < 20000; ++i) {
+ large_output.append("YWFh");
+ }
DataSet data_set = {
{{std::string("ABC")}, std::string("QUJD")},
@@ -1505,6 +1511,7 @@ TEST(function_string_test, function_to_base64_test) {
{{std::string("test ")}, std::string("dGVzdCA=")},
// // 空字符串
{{std::string("")}, std::string("")},
+ {{large_input}, large_output},
};
check_function_all_arg_comb<DataTypeString, true>(func_name, input_types,
data_set);
@@ -1513,6 +1520,12 @@ TEST(function_string_test, function_to_base64_test) {
TEST(function_string_test, function_from_base64_test) {
std::string func_name = "from_base64";
InputTypeSet input_types = {PrimitiveType::TYPE_VARCHAR};
+ std::string large_input;
+ large_input.reserve(120000);
+ for (int i = 0; i < 30000; ++i) {
+ large_input.append("YWFh");
+ }
+ std::string large_output(90000, 'a');
DataSet data_set = {
{{std::string("YXNk5L2g5aW9")}, std::string("asd你好")},
@@ -1523,7 +1536,11 @@ TEST(function_string_test, function_from_base64_test) {
{{std::string("5ZWK5ZOI5ZOI5ZOI8J+YhCDjgILigJTigJQh")},
std::string("啊哈哈哈😄 。——!")},
{{std::string("ò&ø")}, Null()},
+ {{std::string("bad@")}, Null()},
+ {{std::string("====")}, Null()},
+ {{std::string("YQ")}, Null()},
{{std::string("TVl0ZXN0U1RS")}, std::string("MYtestSTR")},
+ {{large_input}, large_output},
{{Null()}, Null()},
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]