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

use-of-uninitialized-value in Field_blob::cached(bool*)

    XMLWordPrintable

Details

    • Can result in hang or crash

    Description

      --source include/have_partition.inc
      CREATE TABLE t1 (c1 INT,c2 INT,c3 TEXT DEFAULT 1,KEY(c2)) PARTITION BY HASH(c1) PARTITIONS 2;
      INSERT INTO t1 () VALUES ();
      SELECT c3,MIN(c2) FROM t1;
      

      Leads to:

      CS 10.11.19 1dab253482dd562457c89deb68082fb647572959 (Optimized, MSAN, Clang 20.1.8-20250804) Build 01/08/2026

      ==594113==WARNING: MemorySanitizer: use-of-uninitialized-value
          #0 0x55555771f7fa in Field_blob::cached(bool*) /test/msan_slow_src/10.11_opt_msan/sql/field.h:4660:27
          #1 0x55555771f7fa in ha_partition::swap_blobs(unsigned char*, Ordered_blob_storage**, bool) /test/msan_slow_src/10.11_opt_msan/sql/ha_partition.cc:7243:29
          #2 0x555557713dd1 in ha_partition::handle_ordered_index_scan(unsigned char*, bool) /test/msan_slow_src/10.11_opt_msan/sql/ha_partition.cc:8049:9
          #3 0x555556432f7e in handler::ha_index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) /test/msan_slow_src/10.11_opt_msan/sql/handler.cc:3670:3
          #4 0x555556940886 in opt_sum_query(THD*, List<TABLE_LIST>&, List<Item>&, Item*) /test/msan_slow_src/10.11_opt_msan/sql/opt_sum.cc:411:23
          #5 0x555556e16027 in JOIN::optimize_inner() /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:2585:10
          #6 0x555556dfad90 in JOIN::optimize() /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:1967:10
          #7 0x555556dfad90 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/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:5271:19
          #8 0x555556df9b27 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:601:10
          #9 0x555556d49d5a in execute_sqlcom_select(THD*, TABLE_LIST*) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:6461:12
          #10 0x555556d3cc5c in mysql_execute_command(THD*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:4040:12
          #11 0x555556d32cf5 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:8219:18
          #12 0x555556d2ce1a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:1924:7
          #13 0x555556d338d8 in do_command(THD*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:1434:17
          #14 0x5555571a835c in do_handle_one_connection(CONNECT*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_connect.cc:1486:11
          #15 0x5555571a7cd2 in handle_one_connection /test/msan_slow_src/10.11_opt_msan/sql/sql_connect.cc:1398:5
          #16 0x7fffe689cb83 in start_thread nptl/pthread_create.c:447:8
          #17 0x7fffe6929d6b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
        Memory was marked as uninitialized
          #0 0x555556363aa1 in __msan_allocated_memory (/test/MSAN_MD010826-mariadb-10.11.19-linux-x86_64-opt/bin/mariadbd+0xe0faa1) (BuildId: 11196b81d08252e74b6f74eb5d4803d04980156f)
          #1 0x555557eff80e in my_malloc /test/msan_slow_src/10.11_opt_msan/mysys/my_malloc.c:116:7
          #2 0x555557ee0fbb in my_multi_malloc /test/msan_slow_src/10.11_opt_msan/mysys/mulalloc.c:59:24
          #3 0x555557710eaa in ha_partition::init_record_priority_queue() /test/msan_slow_src/10.11_opt_msan/sql/ha_partition.cc:5649:8
          #4 0x555557711cf7 in ha_partition::index_init(unsigned int, bool) /test/msan_slow_src/10.11_opt_msan/sql/ha_partition.cc:5778:7
          #5 0x5555569407a6 in handler::ha_index_init(unsigned int, bool) /test/msan_slow_src/10.11_opt_msan/sql/handler.h:3410:19
          #6 0x5555569407a6 in opt_sum_query(THD*, List<TABLE_LIST>&, List<Item>&, Item*) /test/msan_slow_src/10.11_opt_msan/sql/opt_sum.cc:407:17
          #7 0x555556e16027 in JOIN::optimize_inner() /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:2585:10
          #8 0x555556dfad90 in JOIN::optimize() /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:1967:10
          #9 0x555556dfad90 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/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:5271:19
          #10 0x555556df9b27 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/msan_slow_src/10.11_opt_msan/sql/sql_select.cc:601:10
          #11 0x555556d49d5a in execute_sqlcom_select(THD*, TABLE_LIST*) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:6461:12
          #12 0x555556d3cc5c in mysql_execute_command(THD*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:4040:12
          #13 0x555556d32cf5 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:8219:18
          #14 0x555556d2ce1a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:1924:7
          #15 0x555556d338d8 in do_command(THD*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_parse.cc:1434:17
          #16 0x5555571a835c in do_handle_one_connection(CONNECT*, bool) /test/msan_slow_src/10.11_opt_msan/sql/sql_connect.cc:1486:11
          #17 0x5555571a7cd2 in handle_one_connection /test/msan_slow_src/10.11_opt_msan/sql/sql_connect.cc:1398:5
          #18 0x7fffe689cb83 in start_thread nptl/pthread_create.c:447:8
       
      SUMMARY: MemorySanitizer: use-of-uninitialized-value /test/msan_slow_src/10.11_opt_msan/sql/field.h:4660:27 in Field_blob::cached(bool*)
      

      CS 10.11.19 1dab253482dd562457c89deb68082fb647572959 (Debug, MSAN, Clang 20.1.8-20250804) Build 01/08/2026

      ==594502==WARNING: MemorySanitizer: use-of-uninitialized-value
          #0 0x555557ad2294 in Field_blob::cached(bool*) /test/msan_slow_src/10.11_dbg_msan/sql/field.h:4660:27
          #1 0x555557ad2294 in ha_partition::swap_blobs(unsigned char*, Ordered_blob_storage**, bool) /test/msan_slow_src/10.11_dbg_msan/sql/ha_partition.cc:7243:29
          #2 0x555557ac5021 in ha_partition::handle_ordered_index_scan(unsigned char*, bool) /test/msan_slow_src/10.11_dbg_msan/sql/ha_partition.cc:8049:9
          #3 0x55555663b243 in handler::ha_index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) /test/msan_slow_src/10.11_dbg_msan/sql/handler.cc:3670:3
          #4 0x555556bd3b0e in opt_sum_query(THD*, List<TABLE_LIST>&, List<Item>&, Item*) /test/msan_slow_src/10.11_dbg_msan/sql/opt_sum.cc:411:23
          #5 0x55555711eaa8 in JOIN::optimize_inner() /test/msan_slow_src/10.11_dbg_msan/sql/sql_select.cc:2585:10
          #6 0x555557101cb7 in JOIN::optimize() /test/msan_slow_src/10.11_dbg_msan/sql/sql_select.cc:1967:10
          #7 0x555557101cb7 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/msan_slow_src/10.11_dbg_msan/sql/sql_select.cc:5271:19
          #8 0x555557100bc2 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/msan_slow_src/10.11_dbg_msan/sql/sql_select.cc:601:10
          #9 0x555557042dc1 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/msan_slow_src/10.11_dbg_msan/sql/sql_parse.cc:6461:12
          #10 0x555557031fb3 in mysql_execute_command(THD*, bool) /test/msan_slow_src/10.11_dbg_msan/sql/sql_parse.cc:4040:12
          #11 0x5555570264ef in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/msan_slow_src/10.11_dbg_msan/sql/sql_parse.cc:8219:18
          #12 0x55555701ff26 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/msan_slow_src/10.11_dbg_msan/sql/sql_parse.cc:1924:7
          #13 0x555557026fae in do_command(THD*, bool) /test/msan_slow_src/10.11_dbg_msan/sql/sql_parse.cc:1434:17
          #14 0x5555574f457c in do_handle_one_connection(CONNECT*, bool) /test/msan_slow_src/10.11_dbg_msan/sql/sql_connect.cc:1486:11
          #15 0x5555574f3f06 in handle_one_connection /test/msan_slow_src/10.11_dbg_msan/sql/sql_connect.cc:1398:5
          #16 0x7fffe689cb83 in start_thread nptl/pthread_create.c:447:8
          #17 0x7fffe6929d6b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
        Memory was marked as uninitialized
          #0 0x555556554f21 in __msan_allocated_memory (/test/MSAN_MD010826-mariadb-10.11.19-linux-x86_64-dbg/bin/mariadbd+0x1000f21) (BuildId: 6999d25a3f2d8b356f53183bbc8e90162d24134e)
          #1 0x555558555741 in my_malloc /test/msan_slow_src/10.11_dbg_msan/mysys/my_malloc.c:116:7
       
      SUMMARY: MemorySanitizer: use-of-uninitialized-value /test/msan_slow_src/10.11_dbg_msan/sql/field.h:4660:27 in Field_blob::cached(bool*)
      

      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='-O2 -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  010826  4f66ca1b69daf1b7e6a562ca8e86d77a6a70abfe  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      CS  10.6   opt  010826  4f66ca1b69daf1b7e6a562ca8e86d77a6a70abfe  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      CS  10.11  dbg  010826  1dab253482dd562457c89deb68082fb647572959  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  10.11  opt  010826  1dab253482dd562457c89deb68082fb647572959  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  11.4   dbg  010826  c57069561c4fe8f72191d4a2a4a829e5b57537dc  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  11.4   opt  010826  c57069561c4fe8f72191d4a2a4a829e5b57537dc  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  11.8   dbg  010826  eaca80bf3208fb9657b7304b940a6726b4c86213  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  11.8   opt  010826  eaca80bf3208fb9657b7304b940a6726b4c86213  MSAN|use-of-uninitialized-value|sql/field.h|Field_blob::cached|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map
      CS  12.3   dbg  010826  51263b851df7093758e98c7029f091332c1c576f  No bug found                  
      CS  12.3   opt  010826  51263b851df7093758e98c7029f091332c1c576f  No bug found                  
      CS  13.0   dbg  010826  1a4bb1bbfde5fa17ba148cb62678902f11c66a1a  No bug found                  
      CS  13.0   opt  010826  1a4bb1bbfde5fa17ba148cb62678902f11c66a1a  No bug found                  
      CS  13.1   dbg  010826  548c80aeafb6dd2be64f56e902e921a4052b5fe0  No bug found                  
      CS  13.1   opt  010826  548c80aeafb6dd2be64f56e902e921a4052b5fe0  No bug found                  
      ES  10.6   dbg  010826  fcecb2620f25965723d640decede7c018bcb1dcc  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  10.6   opt  010826  fcecb2620f25965723d640decede7c018bcb1dcc  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  11.4   dbg  010826  3b34189bfe675c18c4ced3ef531d016ea74c76f4  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  11.4   opt  010826  3b34189bfe675c18c4ced3ef531d016ea74c76f4  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  11.8   dbg  010826  4694e931d10fecf733c34f83ea2146d31b708eb3  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  11.8   opt  010826  4694e931d10fecf733c34f83ea2146d31b708eb3  MSAN|use-of-uninitialized-value|sql/ha_partition.cc|ha_partition::swap_blobs|ha_partition::handle_ordered_index_scan|handler::ha_index_read_map|opt_sum_query
      ES  12.3   dbg  010826  c86ea989a715d9fbe1a5d760939acec22acfc0df  No bug found                  
      ES  12.3   opt  010826  c86ea989a715d9fbe1a5d760939acec22acfc0df  No bug found                  
      

      Attachments

        Activity

          People

            holyfoot Alexey Botchkov
            saahil Saahil Alam
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 0.15d
                0.15d

                Git Integration

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