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 a6e5395e52b branch-3.0: [fix](struct)Fixed the issue of inserting into 
a struct type string literal with one more subfield causing BE coredump #49485 
(#49552)
a6e5395e52b is described below

commit a6e5395e52b36242b5e08608756c89eed34a3242
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Mar 27 10:06:36 2025 +0800

    branch-3.0: [fix](struct)Fixed the issue of inserting into a struct type 
string literal with one more subfield causing BE coredump #49485 (#49552)
    
    Cherry-picked from #49485
    
    Co-authored-by: amory <[email protected]>
---
 .../data_types/serde/data_type_struct_serde.cpp    |   6 +-
 .../data/insert_p0/test_struct_insert.out          | Bin 625 -> 4698 bytes
 .../suites/insert_p0/test_struct_insert.groovy     | 101 ++++++++++++++++++++-
 3 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/be/src/vec/data_types/serde/data_type_struct_serde.cpp 
b/be/src/vec/data_types/serde/data_type_struct_serde.cpp
index c88b0088e5a..aefea80f0c7 100644
--- a/be/src/vec/data_types/serde/data_type_struct_serde.cpp
+++ b/be/src/vec/data_types/serde/data_type_struct_serde.cpp
@@ -158,7 +158,8 @@ Status 
DataTypeStructSerDe::deserialize_one_cell_from_json(IColumn& column, Slic
             }
             Slice next(slice.data + start_pos, idx - start_pos);
             next.trim_prefix();
-            if (field_pos > elem_size) {
+            // field_pos should always less than elem_size, if not, we should 
return error
+            if (field_pos >= elem_size) {
                 // we should do column revert if error
                 for (size_t j = 0; j < field_pos; j++) {
                     struct_column.get_column(j).pop_back(1);
@@ -188,7 +189,8 @@ Status 
DataTypeStructSerDe::deserialize_one_cell_from_json(IColumn& column, Slic
         (key_added || !is_explicit_names)) {
         Slice next(slice.data + start_pos, idx - start_pos);
         next.trim_prefix();
-        if (field_pos > elem_size) {
+        /// field_pos should always less than elem_size, if not, we should 
return error
+        if (field_pos >= elem_size) {
             // we should do column revert if error
             for (size_t j = 0; j < field_pos; j++) {
                 struct_column.get_column(j).pop_back(1);
diff --git a/regression-test/data/insert_p0/test_struct_insert.out 
b/regression-test/data/insert_p0/test_struct_insert.out
index 3dc160ef7f0..91230f415e2 100644
Binary files a/regression-test/data/insert_p0/test_struct_insert.out and 
b/regression-test/data/insert_p0/test_struct_insert.out differ
diff --git a/regression-test/suites/insert_p0/test_struct_insert.groovy 
b/regression-test/suites/insert_p0/test_struct_insert.groovy
index a845c978580..e2ef485fbcb 100644
--- a/regression-test/suites/insert_p0/test_struct_insert.groovy
+++ b/regression-test/suites/insert_p0/test_struct_insert.groovy
@@ -73,4 +73,103 @@ suite("test_struct_insert") {
 
     // select the table and check whether the data is correct
     qt_select "select * from ${testTable} order by k1"
-}
\ No newline at end of file
+
+  sql "DROP TABLE IF EXISTS test_struct_insert_into"
+    sql """
+    CREATE TABLE IF NOT EXISTS test_struct_insert_into (
+        id INT,
+        s STRUCT<a:INT>,
+        s1 STRUCT<a:INT, b:VARCHAR(20)>,
+        s2 struct<a:int, s:struct<a:int>>,
+        s3 struct<a:int, s:struct<a:int, b:varchar(20)>>,
+        s4 STRUCT<a:INT, s:STRUCT<b:INT, s:STRUCT<c:INT>>>,
+        s5 STRUCT<a:INT, b:STRUCT<c:INT, d:VARCHAR(10)>, e:INT>
+    ) PROPERTIES ("replication_allocation" = "tag.location.default: 1");
+    """
+
+    // insert into table
+    // right cases
+    sql "INSERT INTO test_struct_insert_into VALUES(1, {1}, {1, 'a'}, {1, 
{1}}, {1, {1, 'a'}}, {1, {1, {1}}}, {1, {1, 'a'}, 1})"
+
+    qt_select "select * from test_struct_insert_into order by id"
+
+    sql """INSERT INTO test_struct_insert_into VALUES (
+             2,
+             '{10}',                      -- s: right
+             '{20, "valid"}',             -- s1: right
+             '{30, {31}}',                -- s2: right(outer a=30,s.a=31)
+             '{40, {41, "nested"}}',      -- s3: right(a=40,s.a=41, 
s.b="nested")
+             '{50, {51, {52}}}',          -- s4: right(a=50 -> s.b=51 -> 
s.s.c=52)
+             '{60, {61, "text"}, 70}'     -- s5: right(a=60, b.c=61, 
b.d="text", e=70)
+         );"""
+
+    qt_select "select * from test_struct_insert_into order by id"
+
+    sql """
+    INSERT INTO test_struct_insert_into VALUES (
+         3,
+        '{10, 20}',       -- s:  more -> NULL
+        '{30, "valid"}',  -- s1: right
+        NULL,             -- s2: NULL
+        '{40, {41, "valid"}}',     -- s3: right
+        '{50, {51, null}}',     -- s4: s.s is null
+        '{60, NULL, 70}'  -- s5: b is NULL
+    );
+    """
+
+    qt_select "select * from test_struct_insert_into order by id"
+
+   sql """
+    INSERT INTO test_struct_insert_into VALUES (
+       4,
+       '{"invalid"}',      -- s.a type invalid cast -> s.a is NULL
+       '{40, 50}',         -- right
+       '{50, {"invalid"}}',-- s2.s.a type invalid cast -> s2.s is {"a":null}
+       '{60, {70, 80}}',   -- right
+       '{90, {"invalid", {100}}}',  -- s4.s.b type invalid cast -> s4.s is NULL
+       '{100, {110, 120}, "invalid"}'  -- s5.e type invalid cast -> s5.e is 
NULL
+   );
+   """
+   qt_select "select * from test_struct_insert_into order by id"
+
+   sql """
+   INSERT INTO test_struct_insert_into VALUES (
+       5,
+       '{10}',
+       '{20, "valid"}',
+       '{30, {31, 32}}',       -- s2.s more -> s2.s is NULL
+       '{40, {41, "nested", 42}}',  -- s3.s more -> s3.s is NULL
+       '{50, {51, {52, 53}}}',      -- s4.s.s more -> s4.s.s is NULL
+       '{60, {61, "text", 62}, 70}' -- s5.b more -> s5.b is NULL
+   );
+   """
+  qt_select "select * from test_struct_insert_into order by id"
+  test {
+    sql """
+    INSERT INTO test_struct_insert_into VALUES (
+        6,
+        '{10}',
+        '{20}',                -- s1 less  -> s1 is NULL
+        '{30, {31}}',          -- s2 right
+        '{40, {41}}',          -- s3.s less  -> s3.s is NULL
+        '{50, {51}}',          -- s4.s less  -> s4.s is NULL
+        '{60, {61}, 70}'       -- s5.b less  -> s5.b is NULL
+    );
+    """
+    exception("Size of offsets doesn't match size of column")
+    }
+    qt_select "select * from test_struct_insert_into order by id"
+
+    sql """
+    INSERT INTO test_struct_insert_into VALUES (
+        7,
+        '{10}',                  -- right
+        '{20, }',                -- s1.b is empty
+        '{30, }',                -- s2.s is empty
+        '{40, {41, "nested"}}',   -- right
+        '{50, {51, {52}}}',       -- right  
+        '{60, {61, }, 70}'      -- s5.b.d is empty
+    );
+    """
+     qt_select "select * from test_struct_insert_into order by id"
+}


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

Reply via email to