This is an automated email from the ASF dual-hosted git repository. panxiaolei 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 0078e1f02cb [fix](func) Fix be core dump caused by mem out of bound (#48693) 0078e1f02cb is described below commit 0078e1f02cb9e3511dbf0cf58f410a633637fd2c Author: zxealous <zhouchang...@baidu.com> AuthorDate: Fri Mar 7 13:38:58 2025 +0800 [fix](func) Fix be core dump caused by mem out of bound (#48693) Change-Id: I2483cc57263df1b4373907cd1271a7d04a6056ef ### What problem does this PR solve? Issue Number: close #xxx Related PR: #45062 Problem Summary: data[n] may be negative,resulting in sampling results that may be negative ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [x] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [x] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [x] No. - [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 --> ### Check List (For Reviewer who merge this PR) - [x] Confirm the release note - [x] Confirm test cases - [x] Confirm document - [x] Add branch pick label <!-- Add branch pick label that this PR should merge into --> --- 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 f34d9f91b4d..d87eaaa3dde 100644 --- a/be/src/vec/functions/function_string.cpp +++ b/be/src/vec/functions/function_string.cpp @@ -902,13 +902,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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org