From 1c1f38a6734896dfb482501225035f62af21fe9d Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Sat, 17 May 2025 23:25:08 +0800 Subject: [PATCH] [fix](jsonb) Avoid crashing caused by invalid path (#50978) --- be/src/util/jsonb_document.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/be/src/util/jsonb_document.h b/be/src/util/jsonb_document.h index 0e4fea77f1352f..fb87114f8869ae 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));