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

UBSAN: runtime error: applying zero offset to null pointer in my_strnxfrm_unicode_full_bin on SELECT when using sql_select_limit

    XMLWordPrintable

Details

    Description

      Different from, but possibly related to, MDEV-27081 and MDEV-36003 we have:

      SET sql_select_limit=3;
      SELECT * FROM mysql.user ORDER BY PASSWORD;
      

      Leads to:

      CS 11.8.0 cacaaebf01939d387645fb850ceeec5392496171 (Debug, UBASAN, Clang)

      /test/11.8_dbg_san/strings/ctype-utf8.c:312:67: runtime error: applying zero offset to null pointer
          #0 0x5561678ae89a in my_strnxfrm_unicode_full_bin /test/11.8_dbg_san/strings/ctype-utf8.c:312:67
          #1 0x556165dd978f in charset_info_st::strnxfrm(unsigned char*, unsigned long, unsigned int, unsigned char const*, unsigned long, unsigned int) const /test/11.8_dbg_san/include/m_ctype.h:1126:12
          #2 0x556165dd978f in Type_handler_string_result::make_sort_key_part(unsigned char*, Item*, SORT_FIELD_ATTR const*, String*) const /test/11.8_dbg_san/sql/filesort.cc:1243:11
          #3 0x556165dc7584 in make_sortkey(Sort_param*, unsigned char*) /test/11.8_dbg_san/sql/filesort.cc:3001:41
          #4 0x556165dc7584 in make_sortkey(Sort_param*, unsigned char*, unsigned char*, bool) /test/11.8_dbg_san/sql/filesort.cc:1455:8
          #5 0x556165dc64d1 in Bounded_queue::push(unsigned char*) /test/11.8_dbg_san/sql/filesort.cc:87:5
          #6 0x556165dd4fed in find_all_keys(THD*, Sort_param*, SQL_SELECT*, SORT_INFO*, st_io_cache*, st_io_cache*, Bounded_queue*, unsigned long long*) /test/11.8_dbg_san/sql/filesort.cc:1047:13
          #7 0x556165dcf057 in filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long) /test/11.8_dbg_san/sql/filesort.cc:445:13
          #8 0x556165217620 in create_sort_index(THD*, JOIN*, st_join_table*, Filesort*) /test/11.8_dbg_san/sql/sql_select.cc:27699:14
          #9 0x556165216a66 in st_join_table::sort_table() /test/11.8_dbg_san/sql/sql_select.cc:25191:7
          #10 0x55616516488b in join_init_read_record(st_join_table*) /test/11.8_dbg_san/sql/sql_select.cc:25111:29
          #11 0x5561650e1278 in sub_select(JOIN*, st_join_table*, bool) /test/11.8_dbg_san/sql/sql_select.cc:24106:12
          #12 0x55616517179c in do_select(JOIN*, Procedure*) /test/11.8_dbg_san/sql/sql_select.cc:23620:14
          #13 0x55616516e0f1 in JOIN::exec_inner() /test/11.8_dbg_san/sql/sql_select.cc:5040:50
          #14 0x55616516ba12 in JOIN::exec() /test/11.8_dbg_san/sql/sql_select.cc:4823:8
          #15 0x5561650e5634 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.8_dbg_san/sql/sql_select.cc:5356:21
          #16 0x5561650e3f12 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.8_dbg_san/sql/sql_select.cc:633:10
          #17 0x556164fb9167 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/11.8_dbg_san/sql/sql_parse.cc:6191:12
          #18 0x556164fa4d39 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:3980:12
          #19 0x556164f74588 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7915:18
          #20 0x556164f6864b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #21 0x556164f76fad in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #22 0x55616563a76c in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #23 0x55616563a027 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #24 0x556164979b5c in asan_thread_start(void*) asan_interceptors.cpp.o
          #25 0x151cc469ca93 in start_thread nptl/pthread_create.c:447:8
          #26 0x151cc4729c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/11.8_dbg_san/strings/ctype-utf8.c:312:67 
      

      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)

      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.