Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL)
Description
Similar to MDEV-30931 but in a different function
SELECT (1 DIV(-1/POW(807,14))*1); |
Leads to:
11.0.2 a79abb6517f2fa68b48e61aa3354a0631e3a63f7 (Debug) |
/test/11.0_dbg_san/sql/item_func.cc:1413:6: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
|
/test/11.0_dbg_san/sql/item_func.cc:1444:8: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
|
11.0.2 a79abb6517f2fa68b48e61aa3354a0631e3a63f7 (Debug) |
Version: '11.0.2-MariaDB-debug' socket: '/test/UBASAN_MD250323-mariadb-11.0.2-linux-x86_64-dbg/socket.sock' port: 11466 MariaDB Server
|
2023-03-27 17:40:58 0 [Note] InnoDB: Buffer pool(s) load completed at 230327 17:40:58
|
/test/11.0_dbg_san/sql/item_func.cc:1413:6: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
|
#0 0x5558202d2602 in Item_func_mul::int_op() /test/11.0_dbg_san/sql/item_func.cc:1413
|
#1 0x55581f470eb8 in Item_func_hybrid_field_type::val_int_from_int_op() /test/11.0_dbg_san/sql/item_func.h:849
|
#2 0x55581f470eb8 in Type_handler_int_result::Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type*) const /test/11.0_dbg_san/sql/sql_type.cc:5406
|
#3 0x55581e531687 in Item_func_hybrid_field_type::val_int() /test/11.0_dbg_san/sql/item_func.h:905
|
#4 0x55581f522764 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/11.0_dbg_san/sql/sql_type.cc:7479
|
#5 0x55581f58a9a2 in Type_handler_long::Item_send(Item*, Protocol*, st_value*) const /test/11.0_dbg_san/sql/sql_type.h:5696
|
#6 0x55581dd1359c in Item::send(Protocol*, st_value*) /test/11.0_dbg_san/sql/item.h:1235
|
#7 0x55581decf05c in Protocol::send_result_set_row(List<Item>*) /test/11.0_dbg_san/sql/protocol.cc:1332
|
#8 0x55581e2989ca in select_send::send_data(List<Item>&) /test/11.0_dbg_san/sql/sql_class.cc:3102
|
#9 0x55581ea0fb03 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.0_dbg_san/sql/sql_class.h:5748
|
#10 0x55581ea0fb03 in JOIN::exec_inner() /test/11.0_dbg_san/sql/sql_select.cc:4761
|
#11 0x55581ea1657a in JOIN::exec() /test/11.0_dbg_san/sql/sql_select.cc:4672
|
#12 0x55581ea04d38 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/11.0_dbg_san/sql/sql_select.cc:5153
|
#13 0x55581ea09193 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:611
|
#14 0x55581e588973 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6267
|
#15 0x55581e5e9cce in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
|
#16 0x55581e6195e6 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:7999
|
#17 0x55581e62937a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
|
#18 0x55581e63717f in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
|
#19 0x55581effb459 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
|
#20 0x55581effc974 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
|
#21 0x14e883c42b42 in start_thread nptl/pthread_create.c:442
|
#22 0x14e883cd49ff (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)
|
|
/test/11.0_dbg_san/sql/item_func.cc:1444:8: runtime error: negation of -9223372036854775808 cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself
|
#0 0x5558202d269d in Item_func_mul::int_op() /test/11.0_dbg_san/sql/item_func.cc:1444
|
#1 0x55581f470eb8 in Item_func_hybrid_field_type::val_int_from_int_op() /test/11.0_dbg_san/sql/item_func.h:849
|
#2 0x55581f470eb8 in Type_handler_int_result::Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type*) const /test/11.0_dbg_san/sql/sql_type.cc:5406
|
#3 0x55581e531687 in Item_func_hybrid_field_type::val_int() /test/11.0_dbg_san/sql/item_func.h:905
|
#4 0x55581f522764 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/11.0_dbg_san/sql/sql_type.cc:7479
|
#5 0x55581f58a9a2 in Type_handler_long::Item_send(Item*, Protocol*, st_value*) const /test/11.0_dbg_san/sql/sql_type.h:5696
|
#6 0x55581dd1359c in Item::send(Protocol*, st_value*) /test/11.0_dbg_san/sql/item.h:1235
|
#7 0x55581decf05c in Protocol::send_result_set_row(List<Item>*) /test/11.0_dbg_san/sql/protocol.cc:1332
|
#8 0x55581e2989ca in select_send::send_data(List<Item>&) /test/11.0_dbg_san/sql/sql_class.cc:3102
|
#9 0x55581ea0fb03 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.0_dbg_san/sql/sql_class.h:5748
|
#10 0x55581ea0fb03 in JOIN::exec_inner() /test/11.0_dbg_san/sql/sql_select.cc:4761
|
#11 0x55581ea1657a in JOIN::exec() /test/11.0_dbg_san/sql/sql_select.cc:4672
|
#12 0x55581ea04d38 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/11.0_dbg_san/sql/sql_select.cc:5153
|
#13 0x55581ea09193 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:611
|
#14 0x55581e588973 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6267
|
#15 0x55581e5e9cce in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
|
#16 0x55581e6195e6 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:7999
|
#17 0x55581e62937a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
|
#18 0x55581e63717f in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
|
#19 0x55581effb459 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
|
#20 0x55581effc974 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
|
#21 0x14e883c42b42 in start_thread nptl/pthread_create.c:442
|
#22 0x14e883cd49ff (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)
|
Setup:
Compiled with GCC >=7.5.0 (I use GCC 11.3.0) and:
|
-DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWITH_RAPID=OFF -DWSREP_LIB_WITH_ASAN=ON
|
Set before execution:
|
export UBSAN_OPTIONS=print_stacktrace=1
|
Bug confirmed present in:
MariaDB: 10.3.39 (dbg), 10.3.39 (opt), 10.4.29 (dbg), 10.4.29 (opt), 10.5.20 (dbg), 10.5.20 (opt), 10.6.13 (dbg), 10.6.13 (opt), 10.7.8 (dbg), 10.7.8 (opt), 10.8.8 (dbg), 10.8.8 (opt), 10.9.6 (dbg), 10.9.6 (opt), 10.10.4 (dbg), 10.10.4 (opt), 10.11.3 (dbg), 10.11.3 (opt), 11.0.2 (dbg), 11.0.2 (opt)
Attachments
Issue Links
- relates to
-
MDEV-30931 UBSAN: negation of -X cannot be represented in type 'long long int'; cast to an unsigned type to negate this value to itself in get_interval_value on SELECT
-
- Closed
-
Two problem lines highlighted
10.6 c271057288f71746d1816824f338f2d9c47f67c1 (Source)
/*
First check whether the result can be represented as a
(bool unsigned_flag, longlong value) pair, then check if it is compatible
with this Item's unsigned_flag by calling check_integer_overflow().
Let a = a1 * 2^32 + a0 and b = b1 * 2^32 + b0. Then
a * b = (a1 * 2^32 + a0) * (b1 * 2^32 + b0) = a1 * b1 * 2^64 +
+ (a1 * b0 + a0 * b1) * 2^32 + a0 * b0;
We can determine if the above sum overflows the ulonglong range by
sequentially checking the following conditions:
1. If both a1 and b1 are non-zero.
2. Otherwise, if (a1 * b0 + a0 * b1) is greater than ULONG_MAX.
3. Otherwise, if (a1 * b0 + a0 * b1) * 2^32 + a0 * b0 is greater than
ULONGLONG_MAX.
Since we also have to take the unsigned_flag for a and b into account,
it is easier to first work with absolute values and set the
correct sign later.
*/
if (!args[0]->unsigned_flag && a < 0)
{
a_negative= TRUE;
a= -a; # <<<<<<<< Line 1407
}
if (!args[1]->unsigned_flag && b < 0)
{
b_negative= TRUE;
b= -b; }
a0= 0xFFFFFFFFUL & a;
a1= ((ulonglong) a) >> 32;
b0= 0xFFFFFFFFUL & b;
b1= ((ulonglong) b) >> 32;
if (a1 && b1)
goto err;
res1= (ulonglong) a1 * b0 + (ulonglong) a0 * b1;
if (res1 > 0xFFFFFFFFUL)
goto err;
res1= res1 << 32;
res0= (ulonglong) a0 * b0;
if (test_if_sum_overflows_ull(res1, res0))
goto err;
res= res1 + res0;
if (a_negative != b_negative)
{
if ((ulonglong) res > (ulonglong) LONGLONG_MIN + 1)
goto err;
res= -res; # <<<<<<<< Line 1438
}
else
res_unsigned= TRUE;