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

MSAN: use-of-uninitialized-value in my_charlen_utf8mb3 on SELECT w/ optimizer_trace

    XMLWordPrintable

Details

    Description

      CLI Testcase:

      CREATE TABLE t1 (c3 CHAR) ENGINE=InnoDB;
      ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb3;
      SET optimizer_trace='enabled=on';
      ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
      ALTER TABLE t1 CHANGE c3 c3 TEXT,ALGORITHM=COPY;
      SELECT * FROM t1 WHERE c3 LIKE 'f%';

      MTR Testcase:

      --source include/have_innodb.inc
      CREATE TABLE t1 (c3 CHAR) ENGINE=InnoDB;
      ALTER TABLE t1 CONVERT TO CHARACTER SET utf8mb3;
      SET optimizer_trace='enabled=on';
      ANALYZE TABLE t1 PERSISTENT FOR COLUMNS ALL INDEXES ALL;
      ALTER TABLE t1 CHANGE c3 c3 TEXT,ALGORITHM=COPY;
      SELECT * FROM t1 WHERE c3 LIKE 'f%';

      Leads to:

      CS 13.0.2 172609526b93ac278203607274b70e6b6d8e67fd (Optimized, MSAN, Clang 20.1.8-20250804) Build 07/07/2026

      ==1967952==WARNING: MemorySanitizer: use-of-uninitialized-value
          #0 0x57dd7fa59a63 in my_charlen_utf8mb3 /test/13.0_opt_msan/strings/ctype-utf8.c:664:9
          #1 0x57dd7f9cdfaa in my_ci_charlen /test/13.0_opt_msan/include/m_ctype.h:1443:10
          #2 0x57dd7f9cdfaa in my_append_fix_badly_formed_tail /test/13.0_opt_msan/strings/ctype-mb.c:290:17
          #3 0x57dd7f9cdfaa in my_copy_fix_mb /test/13.0_opt_msan/strings/ctype-mb.c:348:17
          #4 0x57dd7e93b3de in charset_info_st::copy_fix(char*, unsigned long, char const*, unsigned long, unsigned long, MY_STRCOPY_STATUS*) const /test/13.0_opt_msan/include/m_ctype.h:1119:12
          #5 0x57dd7e93b3de in String_copier::well_formed_copy(charset_info_st const*, char*, unsigned long, charset_info_st const*, char const*, unsigned long, unsigned long) /test/13.0_opt_msan/sql/sql_string.cc:1132:26
          #6 0x57dd7dd2700e in Field_longstr::well_formed_copy_with_check(char*, unsigned long, charset_info_st const*, char const*, unsigned long, unsigned long, bool, unsigned int*) /test/13.0_opt_msan/sql/field.h:2372:26
          #7 0x57dd7dd061de in Field_blob::store(char const*, unsigned long, charset_info_st const*) /test/13.0_opt_msan/sql/field.cc:9024:7
          #8 0x57dd7dd22ecc in Field::print_key_part_value(String*, unsigned char const*, unsigned int) /test/13.0_opt_msan/sql/field.cc:11911:3
          #9 0x57dd7e1a4723 in records_in_column_ranges(PARAM*, unsigned int, SEL_ARG*) /test/13.0_opt_msan/sql/opt_range.cc:3466:7
          #10 0x57dd7e1a4723 in calculate_cond_selectivity_for_table(THD*, TABLE*, Item**) /test/13.0_opt_msan/sql/opt_range.cc:3835:26
          #11 0x57dd7e77a3f7 in make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*) /test/13.0_opt_msan/sql/sql_select.cc:6273:13
          #12 0x57dd7e7620a5 in JOIN::optimize_inner() /test/13.0_opt_msan/sql/sql_select.cc:2763:7
          #13 0x57dd7e75d257 in JOIN::optimize() /test/13.0_opt_msan/sql/sql_select.cc:2016:10
          #14 0x57dd7e744364 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/13.0_opt_msan/sql/sql_select.cc:5425:19
          #15 0x57dd7e743e8b in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/13.0_opt_msan/sql/sql_select.cc:636:10
          #16 0x57dd7e690361 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/13.0_opt_msan/sql/sql_parse.cc:6217:12
          #17 0x57dd7e68345b in mysql_execute_command(THD*, bool) /test/13.0_opt_msan/sql/sql_parse.cc:3991:12
          #18 0x57dd7e678cef in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/13.0_opt_msan/sql/sql_parse.cc:7945:18
          #19 0x57dd7e672745 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/13.0_opt_msan/sql/sql_parse.cc:1903:7
          #20 0x57dd7e6797b4 in do_command(THD*, bool) /test/13.0_opt_msan/sql/sql_parse.cc:1437:17
          #21 0x57dd7eb340ec in do_handle_one_connection(CONNECT*, bool) /test/13.0_opt_msan/sql/sql_connect.cc:1510:11
          #22 0x57dd7eb33a6e in handle_one_connection /test/13.0_opt_msan/sql/sql_connect.cc:1422:5
          #23 0x77ec5a49caa3 in start_thread nptl/pthread_create.c:447:8
          #24 0x77ec5a529c6b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
        Memory was marked as uninitialized
          #0 0x57dd7db92971 in __msan_allocated_memory (/test/MSAN_MD070726-mariadb-13.0.2-linux-x86_64-opt/bin/mariadbd+0xf73971) (BuildId: b0458e033cbf6ffe612ed69b6414ea64df9d4998)
          #1 0x57dd7f94c85e in my_malloc /test/13.0_opt_msan/mysys/my_malloc.c:117:7
          #2 0x57dd7f92d478 in alloc_root /test/13.0_opt_msan/mysys/my_alloc.c:294:30
          #3 0x57dd7e1a38f8 in create_key_parts_for_pseudo_indexes(RANGE_OPT_PARAM*, st_bitmap*) /test/13.0_opt_msan/sql/opt_range.cc:3376:33
          #4 0x57dd7e1a38f8 in calculate_cond_selectivity_for_table(THD*, TABLE*, Item**) /test/13.0_opt_msan/sql/opt_range.cc:3795:11
          #5 0x57dd7e77a3f7 in make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*) /test/13.0_opt_msan/sql/sql_select.cc:6273:13
          #6 0x57dd7e7620a5 in JOIN::optimize_inner() /test/13.0_opt_msan/sql/sql_select.cc:2763:7
          #7 0x57dd7e75d257 in JOIN::optimize() /test/13.0_opt_msan/sql/sql_select.cc:2016:10
          #8 0x57dd7e744364 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/13.0_opt_msan/sql/sql_select.cc:5425:19
          #9 0x57dd7e743e8b in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/13.0_opt_msan/sql/sql_select.cc:636:10
          #10 0x57dd7e690361 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/13.0_opt_msan/sql/sql_parse.cc:6217:12
          #11 0x57dd7e68345b in mysql_execute_command(THD*, bool) /test/13.0_opt_msan/sql/sql_parse.cc:3991:12
          #12 0x57dd7e678cef in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/13.0_opt_msan/sql/sql_parse.cc:7945:18
          #13 0x57dd7e672745 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/13.0_opt_msan/sql/sql_parse.cc:1903:7
          #14 0x57dd7e6797b4 in do_command(THD*, bool) /test/13.0_opt_msan/sql/sql_parse.cc:1437:17
          #15 0x57dd7eb340ec in do_handle_one_connection(CONNECT*, bool) /test/13.0_opt_msan/sql/sql_connect.cc:1510:11
          #16 0x57dd7eb33a6e in handle_one_connection /test/13.0_opt_msan/sql/sql_connect.cc:1422:5
          #17 0x77ec5a49caa3 in start_thread nptl/pthread_create.c:447:8
       
      SUMMARY: MemorySanitizer: use-of-uninitialized-value /test/13.0_opt_msan/strings/ctype-utf8.c:664:9 in my_charlen_utf8mb3

      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_MSAN=ON  # Note: WITH_MSAN=ON is auto-ignored when not using clang (MDEV-20377)
      Set before execution:
          export MSAN_OPTIONS=abort_on_error=1:poison_in_dtor=0

      MSAN Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed             
      CS  10.6   dbg  070726  736edbe77ce5db44ea38347280f77d6a304fa3ae  No bug found                  
      CS  10.6   opt  070726  736edbe77ce5db44ea38347280f77d6a304fa3ae  No bug found                  
      CS  10.11  dbg  070726  2be9ba2537aa3ff5836b21489cfca6b0f0ccf80a  No bug found                  
      CS  10.11  opt  070726  2be9ba2537aa3ff5836b21489cfca6b0f0ccf80a  No bug found                  
      CS  11.4   dbg  090726  176589bf19ea6e2261bb3ef57886c13b9c0b6759  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  11.4   opt  090726  176589bf19ea6e2261bb3ef57886c13b9c0b6759  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  11.8   dbg  070726  666b2aca09cb84d59b4ece2185a9200d745cb287  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  11.8   opt  070726  666b2aca09cb84d59b4ece2185a9200d745cb287  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  12.3   dbg  070726  8da34620ac3935814cc7f9ba30bb51a6e2070237  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  12.3   opt  070726  8da34620ac3935814cc7f9ba30bb51a6e2070237  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  13.0   dbg  070726  172609526b93ac278203607274b70e6b6d8e67fd  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  13.0   opt  070726  172609526b93ac278203607274b70e6b6d8e67fd  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  13.1   dbg  070726  fd8cec54af7a9d79749df25ea70dac695b371641  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      CS  13.1   opt  070726  fd8cec54af7a9d79749df25ea70dac695b371641  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  10.6   dbg  070726  07b87fa33b7263c3b46b1a820474f88803d25a04  No bug found                  
      ES  10.6   opt  070726  07b87fa33b7263c3b46b1a820474f88803d25a04  No bug found                  
      ES  11.4   dbg  070726  89bb238190d313ead3b68e508099974e3728515e  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  11.4   opt  070726  89bb238190d313ead3b68e508099974e3728515e  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  11.8   dbg  070726  97386db1d887891fb17e5210536bfe8756bae3cf  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  11.8   opt  070726  97386db1d887891fb17e5210536bfe8756bae3cf  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  12.3   dbg  070726  b96de078339ebc1995fd6185bf5433c72fedbdaf  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb
      ES  12.3   opt  070726  b96de078339ebc1995fd6185bf5433c72fedbdaf  MSAN|use-of-uninitialized-value|strings/ctype-utf8.c|my_charlen_utf8mb3|my_ci_charlen|my_append_fix_badly_formed_tail|my_copy_fix_mb

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            saahil Saahil Alam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1.5h
                1.5h

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.