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

yiguolei 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 1af10e87ba0 [fix](jsonb) Avoid crashing caused by invalid path (#50978)
1af10e87ba0 is described below

commit 1af10e87ba0908ed1c3631755726fcc64e238594
Author: Jerry Hu <[email protected]>
AuthorDate: Sat May 17 23:25:08 2025 +0800

    [fix](jsonb) Avoid crashing caused by invalid path (#50978)
---
 be/src/util/jsonb_document.h                        |  8 ++++++++
 .../conditional_functions/test_json_parse.groovy    | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h
index 8f6d4880789..f67fa79cbd3 100644
--- a/be/src/util/jsonb_document.h
+++ b/be/src/util/jsonb_document.h
@@ -1499,6 +1499,10 @@ inline bool JsonbPath::parsePath(Stream* stream, 
JsonbPath* path) {
         // advance past the .
         stream->skip(1);
 
+        if (stream->exhausted()) {
+            return false;
+        }
+
         // $.[0]
         if (stream->peek() == BEGIN_ARRAY) {
             return parse_array(stream, path);
@@ -1523,6 +1527,10 @@ inline bool JsonbPath::parse_array(Stream* stream, 
JsonbPath* path) {
         stream->set_leg_ptr(const_cast<char*>(stream->position()));
         stream->add_leg_len();
         stream->skip(1);
+        if (stream->exhausted()) {
+            return false;
+        }
+
         if (stream->peek() == END_ARRAY) {
             std::unique_ptr<leg_info> leg(
                     new leg_info(stream->get_leg_ptr(), stream->get_leg_len(), 
0, ARRAY_CODE));
diff --git 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_json_parse.groovy
 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_json_parse.groovy
index a51138774db..5578cf10ecb 100644
--- 
a/regression-test/suites/query_p0/sql_functions/conditional_functions/test_json_parse.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/conditional_functions/test_json_parse.groovy
@@ -49,5 +49,26 @@ suite("test_json_parse") {
     check_fold_consistency "json_parse_error_to_null('null')"
     check_fold_consistency "json_parse_error_to_null('123')"
     check_fold_consistency "json_parse_error_to_null('[1, 2, 3]')"
+
+
+    sql """DROP TABLE IF EXISTS `test_invalid_path_tbl`;"""
+    sql """
+        CREATE TABLE `test_invalid_path_tbl` (
+            `id` int NULL,
+            `v` json NULL,
+            `s` text NULL
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`id`)
+        DISTRIBUTED BY RANDOM BUCKETS AUTO
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1");
+    """
+
+    sql """ insert into test_invalid_path_tbl values (1, '{"key": "value"}', 
'\$.\$.'); """
+
+    test {
+        sql "SELECT id, json_exists_path(v, s) FROM test_invalid_path_tbl;"
+        exception "Json path error: Invalid Json Path for value: \$.\$."
+    }
 }
 


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

Reply via email to