Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-35406

UBSAN runtime error: signed integer overflow on SELECT DATE_ADD/MAKEDATE

    XMLWordPrintable

Details

    Description

      SELECT DATE_ADD('1-1-1',INTERVAL '9223372036854775808-02' YEAR_MONTH) AS result;
      

      Leads to:

      CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Optimized, UBASAN)

      /test/11.2_opt_san/sql/sql_time.cc:1027:63: runtime error: signed integer overflow: -9223372036854775808 * 12 cannot be represented in type 'long int'
      

      CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Optimized, UBASAN)

          #0 0x55e274bc4bb0 in date_add_interval(THD*, st_mysql_time*, interval_type, INTERVAL const&, bool) /test/11.2_opt_san/sql/sql_time.cc:1027
          #1 0x55e27679c6be in Func_handler_date_add_interval::add(THD*, Item*, interval_type, bool, st_mysql_time*) const /test/11.2_opt_san/sql/item_timefunc.h:1711
          #2 0x55e27679c6be in Func_handler_date_add_interval_string::get_date(THD*, Item_handled_func*, st_mysql_time*, date_mode_t) const /test/11.2_opt_san/sql/item_timefunc.h:1824
          #3 0x55e27528e1f8 in Temporal_hybrid::Temporal_hybrid(THD*, Item*, date_mode_t) /test/11.2_opt_san/sql/sql_type.cc:441
          #4 0x55e276702d56 in Temporal_hybrid::Temporal_hybrid(THD*, Item*) /test/11.2_opt_san/sql/sql_type.h:1269
          #5 0x55e276702d56 in Temporal_hybrid::Temporal_hybrid(Item*) /test/11.2_opt_san/sql/sql_type.h:1272
          #6 0x55e276702d56 in Item_handled_func::Handler_temporal_string::val_str_ascii(Item_handled_func*, String*) const /test/11.2_opt_san/sql/item_func.h:647
          #7 0x55e27631b23e in Item_func::val_str_from_val_str_ascii(String*, String*) /test/11.2_opt_san/sql/item_strfunc.cc:104
          #8 0x55e276793a9f in Item_handled_func::Handler_temporal::val_str(Item_handled_func*, String*) const /test/11.2_opt_san/sql/item_func.h:612
          #9 0x55e2752cbbc6 in Type_handler::Item_send_str(Item*, Protocol*, st_value*) const /test/11.2_opt_san/sql/sql_type.cc:7657
          #10 0x55e273b8fcec in Protocol::send_result_set_row(List<Item>*) /test/11.2_opt_san/sql/protocol.cc:1333
          #11 0x55e273f714ba in select_send::send_data(List<Item>&) /test/11.2_opt_san/sql/sql_class.cc:3194
          #12 0x55e27473da01 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.2_opt_san/sql/sql_class.h:5956
          #13 0x55e27473da01 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.2_opt_san/sql/sql_class.h:5946
          #14 0x55e27473da01 in JOIN::exec_inner() /test/11.2_opt_san/sql/sql_select.cc:4909
          #15 0x55e274742483 in JOIN::exec() /test/11.2_opt_san/sql/sql_select.cc:4820
          #16 0x55e27472f94d 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.2_opt_san/sql/sql_select.cc:5358
          #17 0x55e274733550 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.2_opt_san/sql/sql_select.cc:642
          #18 0x55e274268450 in execute_sqlcom_select /test/11.2_opt_san/sql/sql_parse.cc:6177
          #19 0x55e2742d875f in mysql_execute_command(THD*, bool) /test/11.2_opt_san/sql/sql_parse.cc:3984
          #20 0x55e2742e9482 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.2_opt_san/sql/sql_parse.cc:7938
          #21 0x55e2742fb0da in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.2_opt_san/sql/sql_parse.cc:1894
          #22 0x55e27430b486 in do_command(THD*, bool) /test/11.2_opt_san/sql/sql_parse.cc:1407
          #23 0x55e274cdeefc in do_handle_one_connection(CONNECT*, bool) /test/11.2_opt_san/sql/sql_connect.cc:1439
          #24 0x55e274ce152c in handle_one_connection /test/11.2_opt_san/sql/sql_connect.cc:1341
          #25 0x15380b89ca93 in start_thread nptl/pthread_create.c:447
          #26 0x15380b929c3b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Debug, UBASAN)

      /test/11.2_dbg_san/sql/sql_time.cc:1027:63: runtime error: signed integer overflow: -9223372036854775808 * 12 cannot be represented in type 'long int'
      

      CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Debug, UBASAN)

          #0 0x564d026f7b02 in date_add_interval(THD*, st_mysql_time*, interval_type, INTERVAL const&, bool) /test/11.2_dbg_san/sql/sql_time.cc:1027
          #1 0x564d04442930 in Func_handler_date_add_interval::add(THD*, Item*, interval_type, bool, st_mysql_time*) const /test/11.2_dbg_san/sql/item_timefunc.h:1711
          #2 0x564d04442930 in Func_handler_date_add_interval_string::get_date(THD*, Item_handled_func*, st_mysql_time*, date_mode_t) const /test/11.2_dbg_san/sql/item_timefunc.h:1824
          #3 0x564d02eadb60 in Item_handled_func::get_date(THD*, st_mysql_time*, date_mode_t) /test/11.2_dbg_san/sql/item_func.h:865
          #4 0x564d02e45556 in Temporal_hybrid::Temporal_hybrid(THD*, Item*, date_mode_t) /test/11.2_dbg_san/sql/sql_type.cc:441
          #5 0x564d0442cb32 in Temporal_hybrid::Temporal_hybrid(THD*, Item*) /test/11.2_dbg_san/sql/sql_type.h:1269
          #6 0x564d0442cb32 in Temporal_hybrid::Temporal_hybrid(Item*) /test/11.2_dbg_san/sql/sql_type.h:1272
          #7 0x564d0442cb32 in Item_handled_func::Handler_temporal_string::val_str_ascii(Item_handled_func*, String*) const /test/11.2_dbg_san/sql/item_func.h:647
          #8 0x564d02ead2d0 in Item_handled_func::val_str_ascii(String*) /test/11.2_dbg_san/sql/item_func.h:849
          #9 0x564d03fdb430 in Item_func::val_str_from_val_str_ascii(String*, String*) /test/11.2_dbg_san/sql/item_strfunc.cc:104
          #10 0x564d0442ae8d in Item_handled_func::Handler_temporal::val_str(Item_handled_func*, String*) const /test/11.2_dbg_san/sql/item_func.h:612
          #11 0x564d02ead0b0 in Item_handled_func::val_str(String*) /test/11.2_dbg_san/sql/item_func.h:845
          #12 0x564d02e88ecb in Type_handler::Item_send_str(Item*, Protocol*, st_value*) const /test/11.2_dbg_san/sql/sql_type.cc:7657
          #13 0x564d027b0b0e in Type_handler_string_result::Item_send(Item*, Protocol*, st_value*) const /test/11.2_dbg_san/sql/sql_type.h:5534
          #14 0x564d014c70c0 in Item::send(Protocol*, st_value*) /test/11.2_dbg_san/sql/item.h:1255
          #15 0x564d016c83ec in Protocol::send_result_set_row(List<Item>*) /test/11.2_dbg_san/sql/protocol.cc:1333
          #16 0x564d01a72912 in select_send::send_data(List<Item>&) /test/11.2_dbg_san/sql/sql_class.cc:3194
          #17 0x564d0221c46d in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.2_dbg_san/sql/sql_class.h:5956
          #18 0x564d0221c46d in JOIN::exec_inner() /test/11.2_dbg_san/sql/sql_select.cc:4909
          #19 0x564d02222bd6 in JOIN::exec() /test/11.2_dbg_san/sql/sql_select.cc:4820
          #20 0x564d02210dc3 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.2_dbg_san/sql/sql_select.cc:5358
          #21 0x564d022152d4 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.2_dbg_san/sql/sql_select.cc:642
          #22 0x564d01d68dd9 in execute_sqlcom_select /test/11.2_dbg_san/sql/sql_parse.cc:6177
          #23 0x564d01dcd8fc in mysql_execute_command(THD*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:3984
          #24 0x564d01df8351 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.2_dbg_san/sql/sql_parse.cc:7938
          #25 0x564d01e0829b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1894
          #26 0x564d01e16b06 in do_command(THD*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1407
          #27 0x564d0283e791 in do_handle_one_connection(CONNECT*, bool) /test/11.2_dbg_san/sql/sql_connect.cc:1439
          #28 0x564d0283fcb3 in handle_one_connection /test/11.2_dbg_san/sql/sql_connect.cc:1341
          #29 0x15147869ca93 in start_thread nptl/pthread_create.c:447
          #30 0x151478729c3b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      Setup:

      Compiled with a recent version of GCC (I used GCC 11.4.0) and:
          -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWSREP_LIB_WITH_ASAN=ON
      Set before execution:
          export UBSAN_OPTIONS=print_stacktrace=1
      

      Bug confirmed present in:
      MariaDB: 10.5.27 (dbg), 10.5.27 (opt), 10.6.20 (dbg), 10.6.20 (opt), 10.11.10 (dbg), 10.11.10 (opt), 11.2.6 (dbg), 11.2.6 (opt), 11.4.4 (dbg), 11.4.4 (opt), 11.6.2 (dbg), 11.6.2 (opt), 11.7.0 (dbg), 11.7.0 (opt)

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.