From 43fa8e0b8f3bae1ff8493cfd3adb39443da6a809 Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Mon, 18 Apr 2022 22:30:20 +0530 Subject: [PATCH] MDEV-28319: Assertion `cur_step->type & JSON_PATH_KEY' failed in json_find_path Analysis: When trying to find path and handling the match for path, value at current index is not set to 0 for array_counters. This causes wrong current step value which eventually causes wrong cur_step->type value. Fix: Set the value at current index for array_counters to 0. --- mysql-test/suite/json/r/json_table.result | 6 ++++++ mysql-test/suite/json/t/json_table.test | 6 ++++++ strings/json_lib.c | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index a8c96dde5c8..98c16d4d49e 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -1060,5 +1060,11 @@ collation(name) utf8mb4_bin DROP VIEW v1; # +# MDEV-28319: Assertion `cur_step->type & JSON_PATH_KEY' failed in json_find_path +# +SELECT * FROM JSON_TABLE('{"foo":{"bar":1},"qux":2}', '$' COLUMNS(c1 VARCHAR(8) PATH '$[0]', c2 CHAR(8) PATH '$.*.x')) AS js; +c1 c2 +NULL NULL +# # End of 10.9 tests # diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index ace059b7ec4..5bd1c07bdf0 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -909,6 +909,12 @@ SHOW CREATE VIEW v1; SELECT collation(name) FROM v1; DROP VIEW v1; +--echo # +--echo # MDEV-28319: Assertion `cur_step->type & JSON_PATH_KEY' failed in json_find_path +--echo # + +SELECT * FROM JSON_TABLE('{"foo":{"bar":1},"qux":2}', '$' COLUMNS(c1 VARCHAR(8) PATH '$[0]', c2 CHAR(8) PATH '$.*.x')) AS js; + --echo # --echo # End of 10.9 tests --echo # diff --git a/strings/json_lib.c b/strings/json_lib.c index e9f671c5a97..1f1b5f9b604 100644 --- a/strings/json_lib.c +++ b/strings/json_lib.c @@ -1374,7 +1374,6 @@ static int handle_match(json_engine_t *je, json_path_t *p, return json_skip_level(je); array_counters[next_step - p->steps]= 0; - if (next_step->type & JSON_PATH_ARRAY) { int array_size;