diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h index 8f6d4880789c6a..f67fa79cbd32ef 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(stream->position())); stream->add_leg_len(); stream->skip(1); + if (stream->exhausted()) { + return false; + } + if (stream->peek() == END_ARRAY) { std::unique_ptr 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 a51138774dbc4b..5578cf10ecbacb 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: \$.\$." + } }