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

UBSAN: runtime error: X is outside the range of representable values of type 'unsigned long long' on SELECT SLEEP

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      SELECT SLEEP(18446744073709551616);
      

      Leads to (note the slightly different stack on 10.5+10.6 ES/CS versus later versions - i.e. the earlier versions do not have the do_pause() frame):

      CS 10.6.22 643319a7fb1e273797c2a1e46d76cfac0fa1da8f (Optimized, UBASAN) Build 06/06/2025

      /test/10.6_opt_san/sql/item_func.cc:4650:38: runtime error: 1.84467e+28 is outside the range of representable values of type 'unsigned long long'
          #0 0x61f7b863d06a in Item_func_sleep::val_int() /test/10.6_opt_san/sql/item_func.cc:4650:38
          #1 0x61f7b9bb4214 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/10.6_opt_san/sql/sql_type.cc:7630:22
          #2 0x61f7b8b8cf4e in Protocol::send_result_set_row(List<Item>*) /test/10.6_opt_san/sql/protocol.cc:1329:15
          #3 0x61f7b8e4da70 in select_send::send_data(List<Item>&) /test/10.6_opt_san/sql/sql_class.cc:3219:17
          #4 0x61f7b93e413b in JOIN::exec_inner() /test/10.6_opt_san/sql/sql_select.cc:4805:22
          #5 0x61f7b93e04d0 in JOIN::exec() /test/10.6_opt_san/sql/sql_select.cc:4717:3
          #6 0x61f7b9360704 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/10.6_opt_san/sql/sql_select.cc:5196:9
          #7 0x61f7b935f500 in handle_select(THD*, LEX*, select_result*, unsigned long) /test/10.6_opt_san/sql/sql_select.cc:573:10
          #8 0x61f7b92469ef in execute_sqlcom_select(THD*, TABLE_LIST*) /test/10.6_opt_san/sql/sql_parse.cc:6422:12
          #9 0x61f7b9224b9d in mysql_execute_command(THD*, bool) /test/10.6_opt_san/sql/sql_parse.cc:4013:12
          #10 0x61f7b9206680 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/10.6_opt_san/sql/sql_parse.cc:8200:18
          #11 0x61f7b91fd993 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/10.6_opt_san/sql/sql_parse.cc:1908:7
          #12 0x61f7b9208946 in do_command(THD*, bool) /test/10.6_opt_san/sql/sql_parse.cc:1421:17
          #13 0x61f7b98fe15c in do_handle_one_connection(CONNECT*, bool) /test/10.6_opt_san/sql/sql_connect.cc:1386:11
          #14 0x61f7b98fd9aa in handle_one_connection /test/10.6_opt_san/sql/sql_connect.cc:1298:5
          #15 0x61f7b81c23ec in asan_thread_start(void*) crtstuff.c
          #16 0x703a9929ca93 in start_thread nptl/pthread_create.c:447:8
          #17 0x703a99329c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow /test/10.6_opt_san/sql/item_func.cc:4650:38 
      

      CS 12.0.1 f1102da37a3dcdc8b92e0205f0a8bd878704b168 (Debug, UBASAN) Build 06/06/2025

      /test/12.0_dbg_san/sql/item_func.cc:7401:39: runtime error: 1.84467e+28 is outside the range of representable values of type 'unsigned long long'
          #0 0x5ce2364daec8 in do_pause(THD*, Interruptible_wait*, st_mysql_cond*, double) /test/12.0_dbg_san/sql/item_func.cc:7401:39
          #1 0x5ce2364da43c in Item_func_sleep::val_int() /test/12.0_dbg_san/sql/item_func.cc:4666:10
          #2 0x5ce237da4774 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/12.0_dbg_san/sql/sql_type.cc:7745:22
          #3 0x5ce236baf598 in Protocol::send_result_set_row(List<Item>*) /test/12.0_dbg_san/sql/protocol.cc:1359:15
          #4 0x5ce236e85223 in select_send::send_data(List<Item>&) /test/12.0_dbg_san/sql/sql_class.cc:3347:17
          #5 0x5ce236e83842 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/12.0_dbg_san/sql/sql_class.cc:3245:11
          #6 0x5ce237488511 in JOIN::exec_inner() /test/12.0_dbg_san/sql/sql_select.cc:4945:22
          #7 0x5ce237484bf2 in JOIN::exec() /test/12.0_dbg_san/sql/sql_select.cc:4857:8
          #8 0x5ce2373fdc84 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/12.0_dbg_san/sql/sql_select.cc:5390:21
          #9 0x5ce2373fc562 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/12.0_dbg_san/sql/sql_select.cc:634:10
          #10 0x5ce2372c5c47 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/12.0_dbg_san/sql/sql_parse.cc:6166:12
          #11 0x5ce2372a40fe in mysql_execute_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:3954:12
          #12 0x5ce2372821a8 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/12.0_dbg_san/sql/sql_parse.cc:7882:18
          #13 0x5ce237276111 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1877:7
          #14 0x5ce237284bcd in do_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1416:17
          #15 0x5ce237a15a3c in do_handle_one_connection(CONNECT*, bool) /test/12.0_dbg_san/sql/sql_connect.cc:1414:11
          #16 0x5ce237a152f7 in handle_one_connection /test/12.0_dbg_san/sql/sql_connect.cc:1326:5
          #17 0x5ce23606619c in asan_thread_start(void*) crtstuff.c
          #18 0x72fbcce9ca93 in start_thread nptl/pthread_create.c:447:8
          #19 0x72fbccf29c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow /test/12.0_dbg_san/sql/item_func.cc:7401:39 
      

      Setup:

      Compiled with a recent version of Clang (I used Clang 18.1.3) with LLVM 18. Ubuntu instructions:
        # Note: It is strongly recommended to uninstall all old Clang & LLVM packages (ref  dpkg --list | grep -iE 'clang|llvm'  and use  apt purge  and  dpkg --purge  to remove the packages), before installing Clang/LLVM 18
           sudo apt install clang llvm-18 llvm-18-linker-tools llvm-18-runtime llvm-18-tools llvm-18-dev libstdc++-14-dev llvm-dev
      Compiled with: "-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C{,XX}_FLAGS='-march=native -mtune=native'" 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:report_error_type=1   # And you may also want to supress UBSAN startup issues using 'suppressions=UBSAN.filter' in UBSAN_OPTIONS. For an example of UBSAN.filter, which includes current startup issues see: https://github.com/mariadb-corporation/mariadb-qa/blob/master/UBSAN.filter
      

      SAN Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed             
      CS  10.6   dbg  060625  643319a7fb1e273797c2a1e46d76cfac0fa1da8f  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      CS  10.6   opt  060625  643319a7fb1e273797c2a1e46d76cfac0fa1da8f  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      CS  10.11  dbg  060625  11d1ac7285221ab4df7d9ef7cc8ee949b01c9b32  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  10.11  opt  060625  11d1ac7285221ab4df7d9ef7cc8ee949b01c9b32  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  11.4   dbg  060625  8c6cbb336081a5e1ad781df4a9778b61e3b4d73f  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  11.4   opt  060625  8c6cbb336081a5e1ad781df4a9778b61e3b4d73f  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  11.8   dbg  060625  67e6fdee05ead4974fe632e91c38941ade369b0c  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  11.8   opt  060625  67e6fdee05ead4974fe632e91c38941ade369b0c  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  12.0   dbg  060625  f1102da37a3dcdc8b92e0205f0a8bd878704b168  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  12.0   opt  060625  f1102da37a3dcdc8b92e0205f0a8bd878704b168  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  12.1   dbg  060625  4b79d7b8ee557d53a859aedec839b8673585b514  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      CS  12.1   opt  060625  4b79d7b8ee557d53a859aedec839b8673585b514  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      ES  10.5   dbg  060625  ec7bc4f84e490b25f52db7422a1e0e8bbea72fb1  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      ES  10.5   opt  060625  ec7bc4f84e490b25f52db7422a1e0e8bbea72fb1  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      ES  10.6   dbg  060625  8541ea1e4c2fa15789dd162f6ba4b32681f74e61  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      ES  10.6   opt  060625  8541ea1e4c2fa15789dd162f6ba4b32681f74e61  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row|select_send::send_data
      ES  11.4   dbg  060625  1c8b2d3059f5ccb67c042868baca3ee269c6eca7  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      ES  11.4   opt  060625  1c8b2d3059f5ccb67c042868baca3ee269c6eca7  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      ES  11.8   dbg  110625  b9f97a5bc42a4f23889996d2891bcbb0cafcf0bc  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      ES  11.8   opt  110625  b9f97a5bc42a4f23889996d2891bcbb0cafcf0bc  UBSAN|X is outside the range of representable values of type 'unsigned long long'|sql/item_func.cc|do_pause|Item_func_sleep::val_int|Type_handler::Item_send_long|Protocol::send_result_set_row
      

      Note the two different stacks/UniqueID's in the table (scroll to right) as also mentioned above.

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.