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

UBSAN: nullptr-with-offset in grn_db_check_name during Mroonga ALTER TABLE ADD INDEX

    XMLWordPrintable

Details

    • Can result in data loss

    Description

      Testcase is cli compatible using defined startup options:-

      # mysqld options required for replay:  --max_allowed_packet=33554432 --maximum-bulk_insert_buffer_size=1M --maximum-join_buffer_size=1M --maximum-max_heap_table_size=1M --maximum-max_join_size=1M --maximum-myisam_max_sort_file_size=1M --maximum-myisam_mmap_size=1M --maximum-myisam_sort_buffer_size=1M --maximum-optimizer_trace_max_mem_size=1M --maximum-preload_buffer_size=1M --maximum-query_alloc_block_size=1M --maximum-query_prealloc_size=1M --maximum-range_alloc_block_size=1M --maximum-read_buffer_size=1M --maximum-read_rnd_buffer_size=1M --maximum-sort_buffer_size=1M --maximum-tmp_table_size=1M --maximum-transaction_alloc_block_size=1M --maximum-transaction_prealloc_size=1M --log-output=none --secure-file-priv= --sql_mode= --deadlock-timeout-short=10 --deadlock-timeout-long=10 --deadlock-search-depth-short=10 --deadlock-search-depth-long=33
      INSTALL SONAME 'ha_mroonga';#NOERROR;
      CREATE TABLE t1 (c1 DATE,c2 TIME,c3 CHAR,PRIMARY KEY(c1)) ENGINE=Mroonga;#NOERROR;
      INSERT INTO t1 VALUES (DAYOFMONTH(':49:11'),'a','1/2'),(TIMESTAMP(':38:38'),'a',2990);#NOERROR;
      ALTER TABLE t1 DROP INDEX IF EXISTS idx1,ADD INDEX idx1 (c1);#NOERROR;
      

      Leads to:

      CS 10.11.17 8721a00dd38dc0aa1514a3b5ca8c95c6e94af1c9 (Debug, UBASAN, Clang 18.1.3-11) Build 10/05/2026

      /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:799:31: runtime error: applying zero offset to null pointer
          #0 0x692a4aef819c in grn_db_check_name /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:799:31
          #1 0x692a4aefd8c2 in grn_table_create_with_max_n_subrecs /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:1085:7
          #2 0x692a4aefd3a2 in grn_table_create /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:1253:9
          #3 0x692a4b237e3b in grn_ii_builder_create_lexicon /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/ii.c:11583:22
          #4 0x692a4b237e3b in grn_ii_builder_append_source /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/ii.c:12324:8
          #5 0x692a4b232ad8 in grn_ii_build2 /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/ii.c:12847:10
          #6 0x692a4b2bac39 in grn_index_column_build /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/index_column.c:146:13
          #7 0x692a4af2bbed in grn_obj_set_info_source_update /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:8752:7
          #8 0x692a4af2bbed in grn_obj_set_info_source /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:8772:8
          #9 0x692a4af2bbed in grn_obj_set_info /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:8861:10
          #10 0x692a4ad8d8ee in ha_mroonga::storage_create_index(TABLE*, char const*, _grn_obj*, st_mroonga_share*, st_key*, _grn_obj**, _grn_obj**, unsigned int) /test/10.11_dbg_san/storage/mroonga/ha_mroonga.cpp:4158:7
          #11 0x692a4ae58246 in ha_mroonga::storage_inplace_alter_table_add_index(TABLE*, Alter_inplace_info*) /test/10.11_dbg_san/storage/mroonga/ha_mroonga.cpp:14988:18
          #12 0x5757e9811eef in handler::ha_inplace_alter_table(TABLE*, Alter_inplace_info*) /test/10.11_dbg_san/sql/handler.h:4625:11
          #13 0x5757e9811eef in mysql_inplace_alter_table(THD*, TABLE_LIST*, TABLE*, TABLE*, Alter_inplace_info*, MDL_request*, st_ddl_log_state*, TRIGGER_RENAME_PARAM*, Alter_table_ctx*, bool&, unsigned long long&, bool) /test/10.11_dbg_san/sql/sql_table.cc:8133:21
          #14 0x5757e97f7292 in mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, Table_specification_st*, TABLE_LIST*, Recreate_info*, Alter_info*, unsigned int, st_order*, bool, bool) /test/10.11_dbg_san/sql/sql_table.cc:11467:16
          #15 0x5757e9ae510e in Sql_cmd_alter_table::execute(THD*) /test/10.11_dbg_san/sql/sql_alter.cc:688:11
          #16 0x5757e9390174 in mysql_execute_command(THD*, bool) /test/10.11_dbg_san/sql/sql_parse.cc:6201:26
          #17 0x5757e936f634 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/10.11_dbg_san/sql/sql_parse.cc:8223:18
          #18 0x5757e93686d5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/10.11_dbg_san/sql/sql_parse.cc:1924:7
          #19 0x5757e9370dc8 in do_command(THD*, bool) /test/10.11_dbg_san/sql/sql_parse.cc:1434:17
          #20 0x5757e9abe76c in do_handle_one_connection(CONNECT*, bool) /test/10.11_dbg_san/sql/sql_connect.cc:1475:11
          #21 0x5757e9abe041 in handle_one_connection /test/10.11_dbg_san/sql/sql_connect.cc:1387:5
          #22 0x5757e822b37c in asan_thread_start(void*) crtstuff.c
          #23 0x712aa5c9caa3 in start_thread nptl/pthread_create.c:447:8
          #24 0x712aa5d29c6b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/10.11_dbg_san/storage/mroonga/vendor/groonga/lib/db.c:799:31 
      

      Setup:

      Compiled with a recent version of Clang and LLVM. Ubuntu instructions for Clang/LLVM 18:
        # 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 lld-18
      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  100526  d37e50c6d04c7c27362f1668ae86fa592b94fb23  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  10.6   opt  100526  d37e50c6d04c7c27362f1668ae86fa592b94fb23  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  10.11  dbg  100526  8721a00dd38dc0aa1514a3b5ca8c95c6e94af1c9  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  10.11  opt  100526  8721a00dd38dc0aa1514a3b5ca8c95c6e94af1c9  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  11.4   dbg  100526  f279551013d1319f27344080e2c0758f3959cebf  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  11.4   opt  100526  f279551013d1319f27344080e2c0758f3959cebf  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  11.8   dbg  100526  04e09010773caf0b302b2933fff3fe95381a5e13  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  11.8   opt  100526  04e09010773caf0b302b2933fff3fe95381a5e13  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  12.3   dbg  100526  4c371e30f003b601e7485533476208ae27d51937  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  12.3   opt  100526  4c371e30f003b601e7485533476208ae27d51937  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  13.0   dbg  100526  96b3dd0c34427e9338dda1375575a0e05a7cd267  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      CS  13.0   opt  100526  96b3dd0c34427e9338dda1375575a0e05a7cd267  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  10.6   dbg  100526  55cfada6c54d1b08f2372adc1369a5e5e76f472d  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  10.6   opt  100526  55cfada6c54d1b08f2372adc1369a5e5e76f472d  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  11.4   dbg  100526  90f707057d44f1b5c013a0c3672fd12f32ea7085  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  11.4   opt  100526  90f707057d44f1b5c013a0c3672fd12f32ea7085  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  11.8   dbg  100526  d4fbd664a4514441bb3d9042c0089842ee6fc3c8  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  11.8   opt  100526  d4fbd664a4514441bb3d9042c0089842ee6fc3c8  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  12.3   dbg  100526  4063148254974421994024b7cc94f6f2a850177d  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      ES  12.3   opt  100526  4063148254974421994024b7cc94f6f2a850177d  UBSAN|applying zero offset to null pointer|storage/mroonga/vendor/groonga/lib/db.c|grn_db_check_name|grn_table_create_with_max_n_subrecs|grn_table_create|grn_ii_builder_create_lexicon
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            saahil Saahil Alam
            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.