Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
13.3
-
None
-
None
Description
Problem
The test case of MDEV-13189 (an INTERVAL() call whose first argument is a window function) runs without a crash, but an ASan/UBSan build of current main reports an invalid downcast: Item_func_interval::row() does static_cast<Item_row*>(args[0]) and args[0] is an Item_aggregate_ref. The fix of MDEV-13189 ("Item_row did not correctly mark with_window_func flag") stopped the crash, but this cast is still wrong on that path.
How to repeat
Fresh server, default settings, ASan/UBSan build:
create table t1(i int); |
insert into t1 values (1),(2),(10),(20),(30); |
select sum(i) over (order by i), interval(sum(i) over (order by i), 10, 20) from t1; |
For each build I started a fresh server on an empty data directory three times (13.3.0 main, commit 392818112, --no-defaults, TCP) and ran the statements. The ASan/UBSan build uses -fno-sanitize-recover=undefined, so the server stops at the first error. The same error occurred in 3 of 3 runs for each of these four forms of the query: the plain SELECT above, create temporary table x as select ..., create table x as select ..., and create view v as select ...; select * from v;.
Actual result
sql/item_cmpfunc.h:1230:34: runtime error: downcast of address 0x62d00022a0b8 which does not point to an object of type 'Item_row'
|
0x62d00022a0b8: note: object is of type 'Item_aggregate_ref'
|
#0 Item_func_interval::row() const sql/item_cmpfunc.h:1230:34
|
#1 Item_func_interval::val_int() sql/item_cmpfunc.cc:2157:10
|
#2 Item::save_int_in_field(Field*, bool) sql/item.cc:7808:16
|
#3 Type_handler_int_result::Item_save_in_field(Item*, Field*, bool) const sql/sql_type.cc:4593:16
|
#4 Item::save_in_field(Field*, bool) sql/item.cc:7828:30
|
#5 Item_result_field::save_in_result_field(bool) sql/item.h:3781:5
|
#6 save_window_function_values(List<Item_window_func>&, TABLE*, unsigned char*, int*) sql/sql_window.cc:3019:13
|
#7 compute_window_func(THD*, List<Item_window_func>&, List<Cursor_manager>&, TABLE*, SORT_INFO*) sql/sql_window.cc:3174:9
|
#8 Window_func_runner::exec(THD*, TABLE*, SORT_INFO*) sql/sql_window.cc:3307:18
|
#9 Window_funcs_sort::exec(JOIN*, bool) sql/sql_window.cc:3335:25
|
This is the code path where MDEV-13189 crashed (save_window_function_values).
Notes
- Item_func_interval::row() is static_cast<Item_row*>(args[0]) (sql/item_cmpfunc.h:1230). From the sanitizer message args[0] is an Item_aggregate_ref on this path. I did not trace why the row argument is replaced by an aggregate reference there, and I did not check whether the value of the INTERVAL() result is affected (only the sanitizer report was checked). Other builds (debug, optimized) were not run on this statement.
- The tested source tree contains a small local change of the test harness in sql/sql_parse.cc (24 lines: calls to a coverage hook around dispatch_command() in do_command()). The calls are compiled into other builds I use and are not compiled into the ASan/UBSan build used here. The change does not touch the optimizer, window functions or Item classes.
- I did not test other branches or releases.