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

UBSAN: runtime error: X is outside the range of representable values of type 'long long' on INSERT to SET()

Details

    Description

      Also see MDEV-32226.

      # Minimal t/c to reproduce. Removing one '1' from the INSERT will lead to non-reproducibility
      CREATE TABLE t (f SET(''));
      --error WARN_DATA_TRUNCATED
      INSERT INTO t VALUES (111111111111111111111);
      

      Leads to:

      CS 11.8.0 cacaaebf01939d387645fb850ceeec5392496171 (Debug, UBASAN, Clang)

      /test/11.8_dbg_san/sql/field.h:4972:40: runtime error: 1.11111e+20 is outside the range of representable values of type 'long long'
          #0 0x55e31cf25023 in Field_set::store(double) /test/11.8_dbg_san/sql/field.h:4972:40
          #1 0x55e31ce5fa9e in Field_str::store_decimal(my_decimal const*) /test/11.8_dbg_san/sql/field.cc:2471:16
          #2 0x55e31be710e3 in fill_record(THD*, TABLE*, Field**, List<Item>&, bool, bool, bool) /test/11.8_dbg_san/sql/sql_base.cc:9311:18
          #3 0x55e31be722e3 in fill_record_n_invoke_before_triggers(THD*, TABLE*, Field**, List<Item>&, bool, trg_event_type) /test/11.8_dbg_san/sql/sql_base.cc:9366:11
          #4 0x55e31bf9d127 in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_dbg_san/sql/sql_insert.cc:1118:13
          #5 0x55e31c1245d3 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:4485:10
          #6 0x55e31c0ee588 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7915:18
          #7 0x55e31c0e264b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #8 0x55e31c0f0fad in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #9 0x55e31c7b476c in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #10 0x55e31c7b4027 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #11 0x55e31baf3b5c in asan_thread_start(void*) asan_interceptors.cpp.o
          #12 0x14a15549ca93 in start_thread nptl/pthread_create.c:447:8
          #13 0x14a155529c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow /test/11.8_dbg_san/sql/field.h:4972:40 
      

      CS 11.8.0 cacaaebf01939d387645fb850ceeec5392496171 (Optimized, UBASAN, Clang)

      /test/11.8_dbg_san/sql/field.h:4972:40: runtime error: 1.11111e+20 is outside the range of representable values of type 'long long'
          #0 0x55b94aaf7023 in Field_set::store(double) /test/11.8_dbg_san/sql/field.h:4972:40
          #1 0x55b94aa31a9e in Field_str::store_decimal(my_decimal const*) /test/11.8_dbg_san/sql/field.cc:2471:16
          #2 0x55b949a430e3 in fill_record(THD*, TABLE*, Field**, List<Item>&, bool, bool, bool) /test/11.8_dbg_san/sql/sql_base.cc:9311:18
          #3 0x55b949a442e3 in fill_record_n_invoke_before_triggers(THD*, TABLE*, Field**, List<Item>&, bool, trg_event_type) /test/11.8_dbg_san/sql/sql_base.cc:9366:11
          #4 0x55b949b6f127 in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_dbg_san/sql/sql_insert.cc:1118:13
          #5 0x55b949cf65d3 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:4485:10
          #6 0x55b949cc0588 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7915:18
          #7 0x55b949cb464b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #8 0x55b949cc2fad in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #9 0x55b94a38676c in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #10 0x55b94a386027 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #11 0x55b9496c5b5c in asan_thread_start(void*) asan_interceptors.cpp.o
          #12 0x151510c9ca93 in start_thread nptl/pthread_create.c:447:8
          #13 0x151510d29c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow /test/11.8_dbg_san/sql/field.h:4972:40 
      

      Setup:

      Compiled with a recent version of Clang (I used Clang 18.1.3) with LLVM 18. Ubuntu instructions:
           # Note: llvm-17-linker-tools installs /usr/lib/llvm-17/lib/LLVMgold.so, which is needed for compilation, and LLVMgold.so is no longer included in 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 llvm-17-linker-tools
           sudo ln -s /usr/lib/llvm-17/lib/LLVMgold.so /usr/lib/llvm-18/lib/LLVMgold.so
      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
          export ASAN_OPTIONS=quarantine_size_mb=512:atexit=0:detect_invalid_pointer_pairs=3:dump_instruction_bytes=1:abort_on_error=1:allocator_may_return_null=1
      

      Bug confirmed present in:
      MariaDB: 10.5.28 (dbg), 10.5.28 (opt), 10.6.21 (dbg), 10.6.21 (opt), 10.11.11 (dbg), 10.11.11 (opt), 11.4.5 (dbg), 11.4.5 (opt), 11.7.2 (dbg), 11.7.2 (opt), 11.8.0 (dbg), 11.8.0 (opt)

      Confirmed for InnoDB and MyISAM

      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.