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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 9ec51f862d0f6205f270221bc7307f101d2cdfc9
Author: HappenLee <[email protected]>
AuthorDate: Thu Feb 16 16:15:58 2023 +0800

    [Bug](Datetime) Fix date time function mem use after free (#16814)
---
 .../vec/functions/function_date_or_datetime_computation.h | 15 ++++++++-------
 .../datetime_functions/test_date_function.out             |  3 +++
 .../datetime_functions/test_date_function.groovy          |  2 ++
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/be/src/vec/functions/function_date_or_datetime_computation.h 
b/be/src/vec/functions/function_date_or_datetime_computation.h
index b45333b89d..dd25e0fca9 100644
--- a/be/src/vec/functions/function_date_or_datetime_computation.h
+++ b/be/src/vec/functions/function_date_or_datetime_computation.h
@@ -452,8 +452,8 @@ struct DateTimeAddIntervalImpl {
         const auto is_nullable = 
block.get_by_position(result).type->is_nullable();
         if (const auto* sources = 
check_and_get_column<ColumnVector<FromType1>>(source_col.get())) {
             auto col_to = ColumnVector<ToType>::create();
-            const IColumn& delta_column =
-                    
*remove_nullable(block.get_by_position(arguments[1]).column);
+            auto delta_column_ptr = 
remove_nullable(block.get_by_position(arguments[1]).column);
+            const IColumn& delta_column = *delta_column_ptr;
 
             if (is_nullable) {
                 auto null_map = ColumnUInt8::create(input_rows_count, 0);
@@ -545,16 +545,17 @@ struct DateTimeAddIntervalImpl {
             auto col_to = ColumnVector<ToType>::create();
             if (is_nullable) {
                 auto null_map = ColumnUInt8::create(input_rows_count, 0);
+                auto not_nullable_column_ptr_arg1 =
+                        
remove_nullable(block.get_by_position(arguments[1]).column);
                 if (const auto* delta_vec_column = 
check_and_get_column<ColumnVector<FromType2>>(
-                            
*remove_nullable(block.get_by_position(arguments[1]).column))) {
+                            *not_nullable_column_ptr_arg1)) {
                     Op::constant_vector(sources_const->template 
get_value<FromType1>(),
                                         col_to->get_data(), 
null_map->get_data(),
                                         delta_vec_column->get_data());
                 } else {
-                    Op::constant_vector(
-                            sources_const->template get_value<FromType2>(), 
col_to->get_data(),
-                            null_map->get_data(),
-                            
*remove_nullable(block.get_by_position(arguments[1]).column));
+                    Op::constant_vector(sources_const->template 
get_value<FromType2>(),
+                                        col_to->get_data(), 
null_map->get_data(),
+                                        *not_nullable_column_ptr_arg1);
                 }
                 if (const auto* nullable_col = 
check_and_get_column<ColumnNullable>(
                             block.get_by_position(arguments[0]).column.get())) 
{
diff --git 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
index 57136bcf02..5ca1401ab5 100644
--- 
a/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/datetime_functions/test_date_function.out
@@ -590,6 +590,9 @@ true
 -- !sql --
 2019-08-01T13:21:02.111111
 
+-- !sql --
+-1096
+
 -- !sql --
 \N     \N      \N      \N
 2000-02-29     2000-02-29      2000-02-29      2000-02-29
diff --git 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
index f1220233c0..5995bb53a1 100644
--- 
a/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/datetime_functions/test_date_function.groovy
@@ -551,6 +551,8 @@ suite("test_date_function") {
     qt_sql """ select minutes_sub(test_time2,1) result from ${tableName}; """
     //seconds_sub
     qt_sql """ select seconds_sub(test_time2,1) result from ${tableName}; """
+    //datediff
+    qt_sql """ select datediff(test_time2, STR_TO_DATE('2022-08-01 
00:00:00','%Y-%m-%d')) from ${tableName}; """
 
     // test last_day for vec
     sql """ SET enable_vectorized_engine = TRUE; """


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

Reply via email to