Details
-
Bug
-
Status: In Review (View Workflow)
-
Critical
-
Resolution: Unresolved
-
11.4, 13.3
Description
Problem
JSON_ARRAY_INTERSECT and JSON_OBJECT_FILTER_KEYS evaluate a constant argument with val_json() in fix_length_and_dec(). At PREPARE time a placeholder ? has no value yet (state NO_VALUE), so Item_param::can_return_value() reaches its DBUG_ASSERT(0) ("Should not be possible") and a debug build aborts. No EXECUTE is needed.
How to repeat
Default sql_mode, fresh server:
PREPARE s FROM 'SELECT JSON_ARRAY_INTERSECT(?, 1)'; |
PREPARE s FROM 'SELECT JSON_OBJECT_FILTER_KEYS(1, ?)'; |
I started a fresh server on an empty data directory three times for each statement (debug build of 13.3.0 main, --no-defaults) and ran it once: the PREPARE hit the assertion in 3 of 3 runs for each of the two statements.
Statements that do not crash on the same build (3 of 3 fresh servers each): PREPARE s FROM 'SELECT JSON_ARRAY_INTERSECT(1, ?)', ... JSON_ARRAY_INTERSECT(1, 2), ... JSON_OBJECT_FILTER_KEYS(?, 1), ... JSON_OBJECT_FILTER_KEYS(?, NULL), ... JSON_OBJECT_FILTER_KEYS(1, 2). One fresh server each, no crash: JSON_SCHEMA_VALID(?, ''{}'') (the MDEV-31599 statement, now fixed), JSON_EQUALS(?, 1), JSON_OVERLAPS(?, 1), JSON_NORMALIZE
, JSON_OBJECT_TO_ARRAY
, JSON_CONTAINS(?, 1), JSON_VALID
. One fresh server each, crash: JSON_ARRAY_INTERSECT(?, ?), JSON_ARRAY_INTERSECT(?, JSON_ARRAY(1)), JSON_OBJECT_FILTER_KEYS(?, ?), JSON_OBJECT_FILTER_KEYS(JSON_OBJECT(1,2), ?).
Actual result
Debug build, SIGABRT while preparing the statement, the client loses the connection:
sql/item.cc:5169: bool Item_param::can_return_value() const: Assertion `0' failed.
|
Item_param::can_return_value() const
|
Item_func_json_array_intersect::fix_length_and_dec(THD*) (or Item_func_json_object_filter_keys::fix_length_and_dec(THD*))
|
Item_func::fix_fields(THD*, Item**)
|
setup_fields(THD*, Bounds_checked_array<Item*>, List<Item>&, enum_column_usage, List<Item>*, List<Item>*, bool, THD_WHERE)
|
JOIN::prepare(...)
|
Prepared_statement::prepare(...)
|
Notes
In sql/item_jsonfunc.cc, Item_func_json_array_intersect::fix_length_and_dec() starts with String *js1= args[0]>val_json(&tmp_js1); and Item_func_json_object_filter_keys::fix_length_and_dec() starts with String *js2= args[1]>val_json(&tmp_js2);, without checking whether that argument is a placeholder with no value; the argument that crashes is the one read there. MDEV-31599 had the same call in Item_func_json_schema_valid::fix_length_and_dec() and was fixed for that function; these two functions have the same pattern. I did not test a fix and did not test release builds, where the NO_VALUE case returns false.