This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new 79df82ba620 branch-3.0: [fix](func) Fix be core dump caused by mem out
of bound #48693 (#48845)
79df82ba620 is described below
commit 79df82ba6204409e2a2563f5c302a0ac8f8f3dc6
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Mar 10 14:53:47 2025 +0800
branch-3.0: [fix](func) Fix be core dump caused by mem out of bound #48693
(#48845)
Cherry-picked from #48693
Co-authored-by: zxealous <[email protected]>
---
be/src/vec/functions/function_string.cpp | 14 +++---
.../data/function_p0/test_function_string.out | Bin 0 -> 121 bytes
.../suites/function_p0/test_function_string.groovy | 50 +++++++++++++++++++++
3 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/be/src/vec/functions/function_string.cpp
b/be/src/vec/functions/function_string.cpp
index 1f88c0f5bcf..dad2d33c1cb 100644
--- a/be/src/vec/functions/function_string.cpp
+++ b/be/src/vec/functions/function_string.cpp
@@ -888,13 +888,15 @@ struct StringSpace {
ColumnString::Offsets& res_offsets) {
res_offsets.resize(data.size());
size_t input_size = res_offsets.size();
- // sample to get approximate best reserve size
- if (input_size > 4) {
- res_data.reserve(((data[0] + data[input_size >> 1] +
data[input_size >> 2] +
- data[input_size - 1]) >>
- 2) *
- input_size);
+ int64_t total_size = 0;
+ for (size_t i = 0; i < input_size; ++i) {
+ if (data[i] > 0) {
+ total_size += data[i];
+ }
}
+ ColumnString::check_chars_length(total_size, input_size);
+ res_data.reserve(total_size);
+
for (size_t i = 0; i < input_size; ++i) {
if (data[i] > 0) [[likely]] {
res_data.resize_fill(res_data.size() + data[i], ' ');
diff --git a/regression-test/data/function_p0/test_function_string.out
b/regression-test/data/function_p0/test_function_string.out
new file mode 100644
index 00000000000..226d3e675f3
Binary files /dev/null and
b/regression-test/data/function_p0/test_function_string.out differ
diff --git a/regression-test/suites/function_p0/test_function_string.groovy
b/regression-test/suites/function_p0/test_function_string.groovy
new file mode 100644
index 00000000000..5aa46fb6c52
--- /dev/null
+++ b/regression-test/suites/function_p0/test_function_string.groovy
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_function_string") {
+
+ sql """ set enable_nereids_planner=true; """
+ sql """ set enable_fallback_to_original_planner=false; """
+
+ sql """
+ drop table if exists test_tb_function_space;
+ """
+
+ sql """
+ CREATE TABLE `test_tb_function_space` (
+ `k1` bigint NULL,
+ `k2` text NULL
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`k1`)
+ DISTRIBUTED BY HASH(`k1`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1"
+ );
+ """
+ sql """
+ insert into test_tb_function_space values ('-126', 'a'),('-125',
'a'),('-124', 'a'),('-123', 'a'),('-121', 'a'),('2', 'a');
+ """
+
+ qt_sql """
+ select concat(space(k1), k2) as k from test_tb_function_space order by
k;
+ """
+
+ sql """
+ drop table if exists test_tb_function_space;
+ """
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]