Skip to content

Commit ff72a94

Browse files
MDEV-26392: Crash with json_get_path_next and 10.5.12
Analysis: When we skip level when path is found, it changes the state of the json engine. This breaks the sequence for json_get_path_next() which is called at the end to ensure json document is valid and leads to crash. Fix: Use json_scan_next() at the end to check if json document has correct syntax (is valid).
1 parent 0459d2c commit ff72a94

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mysql-test/main/func_json.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,5 +1611,17 @@ SELECT json_object('a', coalesce(json_object('b', 'c')));
16111611
json_object('a', coalesce(json_object('b', 'c')))
16121612
{"a": {"b": "c"}}
16131613
#
1614+
# MDEV-26392: Crash with json_get_path_next and 10.5.12
1615+
#
1616+
CREATE TABLE arrNestTest (
1617+
id VARCHAR(80) AS (JSON_COMPACT(JSON_EXTRACT(doc, "$._id"))) UNIQUE KEY,
1618+
doc JSON,
1619+
CONSTRAINT id_not_null CHECK(id IS NOT NULL));
1620+
INSERT INTO test.arrNestTest (doc) VALUES ('{ "_id" : { "$oid" : "611c0a463b150154132f6636" }, "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : 1.0 } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }');
1621+
SELECT * FROM arrNestTest;
1622+
id doc
1623+
{"$oid":"611c0a463b150154132f6636"} { "_id" : { "$oid" : "611c0a463b150154132f6636" }, "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : 1.0 } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }
1624+
DROP TABLE arrNestTest;
1625+
#
16141626
# End of 10.5 tests
16151627
#

mysql-test/main/func_json.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,18 @@ DROP TABLE t2;
10541054
SELECT json_object('a', if(1, json_object('b', 'c'), json_object('e', 'f')));
10551055
SELECT json_object('a', coalesce(json_object('b', 'c')));
10561056

1057+
--echo #
1058+
--echo # MDEV-26392: Crash with json_get_path_next and 10.5.12
1059+
--echo #
1060+
1061+
CREATE TABLE arrNestTest (
1062+
id VARCHAR(80) AS (JSON_COMPACT(JSON_EXTRACT(doc, "$._id"))) UNIQUE KEY,
1063+
doc JSON,
1064+
CONSTRAINT id_not_null CHECK(id IS NOT NULL));
1065+
1066+
INSERT INTO test.arrNestTest (doc) VALUES ('{ "_id" : { "$oid" : "611c0a463b150154132f6636" }, "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : [ { "a" : 1.0 } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] } ] }');
1067+
SELECT * FROM arrNestTest;
1068+
DROP TABLE arrNestTest;
10571069

10581070
--echo #
10591071
--echo # End of 10.5 tests

sql/item_jsonfunc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ String *Item_func_json_extract::read_json(String *str,
994994
if (!possible_multiple_values)
995995
{
996996
/* Loop to the end of the JSON just to make sure it's valid. */
997-
while (json_get_path_next(&je, &p) == 0) {}
997+
while (json_scan_next(&je) == 0) {}
998998
break;
999999
}
10001000
}

0 commit comments

Comments
 (0)