This is an automated email from the ASF dual-hosted git repository.

Mryange 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 5a60cad9909 [fix](function) Handle constant NULL arrays in array 
pushback (#68380)
5a60cad9909 is described below

commit 5a60cad9909723699a2a74a4212ad076947c57c4
Author: Mryange <[email protected]>
AuthorDate: Wed Sep 23 17:22:55 2026 +0800

    [fix](function) Handle constant NULL arrays in array pushback (#68380)
    
    `array_pushback` and its `array_append` alias could read past the end of
    the NULL bitmap when the array argument was a constant NULL column
    evaluated for multiple rows. This caused unstable NULL propagation and
    could lead to undefined behavior. The implementation now uses the
    constant-column row index for both the NULL bitmap and array offsets,
    preserving scalar NULL semantics across all input rows.
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [ ] 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:
        - [ ] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [ ] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 .../function/array/function_array_pushback.cpp     |  7 +++--
 .../test_array_functions_by_literal.out            | 36 ++++++++++++++++++++++
 .../test_array_functions_by_literal.groovy         |  2 ++
 3 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/be/src/exprs/function/array/function_array_pushback.cpp 
b/be/src/exprs/function/array/function_array_pushback.cpp
index 898c4d29690..7097613c7e2 100644
--- a/be/src/exprs/function/array/function_array_pushback.cpp
+++ b/be/src/exprs/function/array/function_array_pushback.cpp
@@ -93,14 +93,15 @@ public:
 
         size_t off = 0;
         for (size_t i = 0; i < input_rows_count; ++i) {
-            if (array_null_map && array_null_map[i]) {
+            const size_t src_index = index_check_const(i, src_const);
+            if (array_null_map && array_null_map[src_index]) {
                 result_null_map[i] = 1;
                 result_offset_col[i] = off;
                 continue;
             }
 
-            size_t src_off = src_offset_col[index_check_const(i, src_const) - 
1];
-            size_t src_len = src_offset_col[index_check_const(i, src_const)] - 
src_off;
+            size_t src_off = src_offset_col[src_index - 1];
+            size_t src_len = src_offset_col[src_index] - src_off;
             result_nested_data_col.insert_range_from(src_nested_data_col, 
src_off, src_len);
 
             result_nested_data_col.insert((*right_column)[index_check_const(i, 
right_const)]);
diff --git 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
index 5ebef1618f9..9fe328a301f 100644
--- 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
+++ 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
@@ -932,6 +932,42 @@ _
 -- !sql --
 [null, null, null, null, 80]
 
+-- !sql --
+0      \N
+1      \N
+2      \N
+3      \N
+4      \N
+5      \N
+6      \N
+7      \N
+8      \N
+9      \N
+10     \N
+11     \N
+12     \N
+13     \N
+14     \N
+15     \N
+
+-- !sql --
+0      \N
+1      \N
+2      \N
+3      \N
+4      \N
+5      \N
+6      \N
+7      \N
+8      \N
+9      \N
+10     \N
+11     \N
+12     \N
+13     \N
+14     \N
+15     \N
+
 -- !sql --
 [0, 2, 129]
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
index b51a0b6bd6b..600c6e3db93 100644
--- 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
@@ -386,6 +386,8 @@ suite("test_array_functions_by_literal") {
         qt_sql "select array_pushback(array(cast (111.111 as 
decimalv3(6,3)),cast (222.222 as decimalv3(6,3))), cast (333.333 as 
decimalv3(6,3)))"
         qt_sql "select array_pushback([null,null], null)"
         qt_sql "select array_pushback([null,null,null,null], 80)"
+        qt_sql "select number, array_pushback(cast(null as array<int>), 
number) from numbers('number'='16') order by number"
+        qt_sql "select number, array_append(cast(null as array<int>), number) 
from numbers('number'='16') order by number"
 
         // array_cum_sum
         qt_sql "select array_cum_sum([0, 2, 127])"


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to