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

UBSAN double float-cast-overflow on get_lock()

    XMLWordPrintable

Details

    • Not for Release Notes

    Description

      SELECT get_lock('',18446744073709551616)=0;
      

      Leads to:

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

      /test/12.0_dbg_san/sql/item_func.cc:4299:47: runtime error: 1.84467e+19 is outside the range of representable values of type 'long long'
          #0 0x56614c19dd0d in Item_func_get_lock::val_int() /test/12.0_dbg_san/sql/item_func.cc:4299:47
          #1 0x56614c3237d6 in Arg_comparator::compare_int_signed() /test/12.0_dbg_san/sql/item_cmpfunc.cc:1028:24
          #2 0x56614c336731 in Arg_comparator::compare() /test/12.0_dbg_san/sql/item_cmpfunc.h:114:33
          #3 0x56614c336731 in Item_func_eq::val_bool() /test/12.0_dbg_san/sql/item_cmpfunc.cc:1912:18
          #4 0x56614c1f9ed5 in Item_bool_func::val_int() /test/12.0_dbg_san/sql/item_cmpfunc.h:245:12
          #5 0x56614da6c774 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/12.0_dbg_san/sql/sql_type.cc:7745:22
          #6 0x56614c877598 in Protocol::send_result_set_row(List<Item>*) /test/12.0_dbg_san/sql/protocol.cc:1359:15
          #7 0x56614cb4d223 in select_send::send_data(List<Item>&) /test/12.0_dbg_san/sql/sql_class.cc:3347:17
          #8 0x56614cb4b842 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
          #9 0x56614d150511 in JOIN::exec_inner() /test/12.0_dbg_san/sql/sql_select.cc:4945:22
          #10 0x56614d14cbf2 in JOIN::exec() /test/12.0_dbg_san/sql/sql_select.cc:4857:8
          #11 0x56614d0c5c84 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
          #12 0x56614d0c4562 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/12.0_dbg_san/sql/sql_select.cc:634:10
          #13 0x56614cf8dc47 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/12.0_dbg_san/sql/sql_parse.cc:6166:12
          #14 0x56614cf6c0fe in mysql_execute_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:3954:12
          #15 0x56614cf4a1a8 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/12.0_dbg_san/sql/sql_parse.cc:7882:18
          #16 0x56614cf3e111 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1877:7
          #17 0x56614cf4cbcd in do_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1416:17
          #18 0x56614d6dda3c in do_handle_one_connection(CONNECT*, bool) /test/12.0_dbg_san/sql/sql_connect.cc:1414:11
          #19 0x56614d6dd2f7 in handle_one_connection /test/12.0_dbg_san/sql/sql_connect.cc:1326:5
          #20 0x56614bd2e19c in asan_thread_start(void*) crtstuff.c
          #21 0x7700f849ca93 in start_thread nptl/pthread_create.c:447:8
          #22 0x7700f8529c3b 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:4299:47 
      

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

      /test/12.0_dbg_san/sql/item_func.cc:4305:25: runtime error: 1.84467e+19 is outside the range of representable values of type 'long long'
          #0 0x56614c19dcf2 in Item_func_get_lock::val_int() /test/12.0_dbg_san/sql/item_func.cc:4305:25
          #1 0x56614c3237d6 in Arg_comparator::compare_int_signed() /test/12.0_dbg_san/sql/item_cmpfunc.cc:1028:24
          #2 0x56614c336731 in Arg_comparator::compare() /test/12.0_dbg_san/sql/item_cmpfunc.h:114:33
          #3 0x56614c336731 in Item_func_eq::val_bool() /test/12.0_dbg_san/sql/item_cmpfunc.cc:1912:18
          #4 0x56614c1f9ed5 in Item_bool_func::val_int() /test/12.0_dbg_san/sql/item_cmpfunc.h:245:12
          #5 0x56614da6c774 in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /test/12.0_dbg_san/sql/sql_type.cc:7745:22
          #6 0x56614c877598 in Protocol::send_result_set_row(List<Item>*) /test/12.0_dbg_san/sql/protocol.cc:1359:15
          #7 0x56614cb4d223 in select_send::send_data(List<Item>&) /test/12.0_dbg_san/sql/sql_class.cc:3347:17
          #8 0x56614cb4b842 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
          #9 0x56614d150511 in JOIN::exec_inner() /test/12.0_dbg_san/sql/sql_select.cc:4945:22
          #10 0x56614d14cbf2 in JOIN::exec() /test/12.0_dbg_san/sql/sql_select.cc:4857:8
          #11 0x56614d0c5c84 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
          #12 0x56614d0c4562 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/12.0_dbg_san/sql/sql_select.cc:634:10
          #13 0x56614cf8dc47 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/12.0_dbg_san/sql/sql_parse.cc:6166:12
          #14 0x56614cf6c0fe in mysql_execute_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:3954:12
          #15 0x56614cf4a1a8 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/12.0_dbg_san/sql/sql_parse.cc:7882:18
          #16 0x56614cf3e111 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1877:7
          #17 0x56614cf4cbcd in do_command(THD*, bool) /test/12.0_dbg_san/sql/sql_parse.cc:1416:17
          #18 0x56614d6dda3c in do_handle_one_connection(CONNECT*, bool) /test/12.0_dbg_san/sql/sql_connect.cc:1414:11
          #19 0x56614d6dd2f7 in handle_one_connection /test/12.0_dbg_san/sql/sql_connect.cc:1326:5
          #20 0x56614bd2e19c in asan_thread_start(void*) crtstuff.c
          #21 0x7700f849ca93 in start_thread nptl/pthread_create.c:447:8
          #22 0x7700f8529c3b 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:4305:25 
      

      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 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  10.6   opt  060625  643319a7fb1e273797c2a1e46d76cfac0fa1da8f  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  10.11  dbg  060625  11d1ac7285221ab4df7d9ef7cc8ee949b01c9b32  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  10.11  opt  060625  11d1ac7285221ab4df7d9ef7cc8ee949b01c9b32  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  11.4   dbg  060625  8c6cbb336081a5e1ad781df4a9778b61e3b4d73f  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  11.4   opt  060625  8c6cbb336081a5e1ad781df4a9778b61e3b4d73f  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  11.8   dbg  060625  67e6fdee05ead4974fe632e91c38941ade369b0c  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  11.8   opt  060625  67e6fdee05ead4974fe632e91c38941ade369b0c  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  12.0   dbg  060625  f1102da37a3dcdc8b92e0205f0a8bd878704b168  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  12.0   opt  060625  f1102da37a3dcdc8b92e0205f0a8bd878704b168  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  12.1   dbg  060625  4b79d7b8ee557d53a859aedec839b8673585b514  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      CS  12.1   opt  060625  4b79d7b8ee557d53a859aedec839b8673585b514  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  10.5   dbg  060625  ec7bc4f84e490b25f52db7422a1e0e8bbea72fb1  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_int
      ES  10.5   opt  060625  ec7bc4f84e490b25f52db7422a1e0e8bbea72fb1  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_int
      ES  10.6   dbg  060625  8541ea1e4c2fa15789dd162f6ba4b32681f74e61  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  10.6   opt  060625  8541ea1e4c2fa15789dd162f6ba4b32681f74e61  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  11.4   dbg  060625  1c8b2d3059f5ccb67c042868baca3ee269c6eca7  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  11.4   opt  060625  1c8b2d3059f5ccb67c042868baca3ee269c6eca7  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  11.8   dbg  110625  b9f97a5bc42a4f23889996d2891bcbb0cafcf0bc  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      ES  11.8   opt  110625  b9f97a5bc42a4f23889996d2891bcbb0cafcf0bc  UBSAN|X is outside the range of representable values of type 'long long'|sql/item_func.cc|Item_func_get_lock::val_int|Arg_comparator::compare_int_signed|Arg_comparator::compare|Item_func_eq::val_bool
      

      get_lock() manual reference

      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.