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

Assertion `0' failed in create_histogram, UBSAN invalid-enum-load in Column_stat::get_stat_values and create_histogram

Details

    Description

      SET sql_mode='';
      INSERT INTO mysql.column_stats VALUES ('test','t','c',0,0,0,0,0,0,0,0);
      CREATE TABLE t (c INT);
      INSERT INTO t VALUES (0);
      

      Leads to:

      CS 11.8.1 33e0796e7a154e02a5e53c55cefc5d6feb4f5e6d (Debug) Build 15/02/2025

      mariadbd: /test/11.8_dbg/sql/sql_statistics.cc:1728: Histogram_base *create_histogram(MEM_ROOT *, Histogram_type): Assertion `0' failed.
      

      CS 11.8.1 33e0796e7a154e02a5e53c55cefc5d6feb4f5e6d (Debug) Build 15/02/2025

      Core was generated by `/test/MD150225-mariadb-11.8.1-linux-x86_64-dbg/bin/mariadbd --no-defaults --max'.
      Program terminated with signal SIGABRT, Aborted.
      Download failed: Invalid argument.  Continuing without source file ./nptl/./nptl/pthread_kill.c.
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
       
      [Current thread is 1 (LWP 3538637)]
      (gdb) bt
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
      #1  __pthread_kill_internal (signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:78
      #2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6)at ./nptl/pthread_kill.c:89
      #3  0x000014c78044526e in __GI_raise (sig=sig@entry=6)at ../sysdeps/posix/raise.c:26
      #4  0x000014c7804288ff in __GI_abort () at ./stdlib/abort.c:79
      #5  0x000014c78042881b in __assert_fail_base (fmt=0x14c7805d01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x56404e1903bc "0", file=file@entry=0x56404e10910a "/test/11.8_dbg/sql/sql_statistics.cc", line=line@entry=1728, function=function@entry=0x56404e10915b "Histogram_base *create_histogram(MEM_ROOT *, Histogram_type)") at ./assert/assert.c:94
      #6  0x000014c78043b507 in __assert_fail (assertion=0x56404e1903bc "0", file=0x56404e10910a "/test/11.8_dbg/sql/sql_statistics.cc", line=1728, function=0x56404e10915b "Histogram_base *create_histogram(MEM_ROOT *, Histogram_type)") at ./assert/assert.c:103
      #7  0x000056404d1c9db2 in create_histogram (mem_root=0x14c718076988, hist_type=4294967295) at /test/11.8_dbg/sql/sql_statistics.cc:1728
      #8  0x000056404d1d5f91 in Column_stat::get_stat_values (this=0x14c7780e0a78, read_stats=0x14c718076a50, mem_root=0x14c718076988, want_histograms=true)at /test/11.8_dbg/sql/sql_statistics.cc:1268
      #9  0x000056404d1cc608 in read_statistics_for_table (thd=0x14c718000d58, table=0x14c71803e118, stat_tables=0x14c7780e2530, force_reload=false, want_histograms=true) at /test/11.8_dbg/sql/sql_statistics.cc:3096
      #10 0x000056404d1cbf58 in read_statistics_for_tables (thd=0x14c718000d58, tables=0x14c718019e00, force_reload=false)at /test/11.8_dbg/sql/sql_statistics.cc:3354
      #11 0x000056404d1cb8ec in read_statistics_for_tables_if_needed (thd=0x14c718000d58, tables=0x14c718019e00)at /test/11.8_dbg/sql/sql_statistics.cc:3213
      #12 0x000056404d012903 in open_and_lock_tables (thd=0x14c718000d58, options=@0x14c718006630: {m_options = DDL_options_st::OPT_NONE}, tables=0x14c718019e00, derived=true, flags=0, prelocking_strategy=0x14c7780e4de0) at /test/11.8_dbg/sql/sql_base.cc:5665
      #13 0x000056404d021bae in open_and_lock_tables (thd=0x14c718000d58, tables=0x14c718019e00, derived=true, flags=0)at /test/11.8_dbg/sql/sql_base.h:535
      #14 0x000056404d06c675 in mysql_insert (thd=0x14c718000d58, table_list=0x14c718019e00, fields=@0x14c718005fe0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x56404ec9a6f0 <end_of_list>, last = 0x14c718005fe0, elements = 0}, <No data fields>}, values_list=@0x14c718006028: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14c71801aaa0, last = 0x14c71801aaa0, elements = 1}, <No data fields>}, update_fields=@0x14c718006010: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x56404ec9a6f0 <end_of_list>, last = 0x14c718006010, elements = 0}, <No data fields>}, update_values=@0x14c718005ff8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x56404ec9a6f0 <end_of_list>, last = 0x14c718005ff8, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0)at /test/11.8_dbg/sql/sql_insert.cc:784
      #15 0x000056404d0ccad2 in mysql_execute_command (thd=0x14c718000d58, is_called_from_prepared_stmt=false) at /test/11.8_dbg/sql/sql_parse.cc:4484
      #16 0x000056404d0c27d4 in mysql_parse (thd=0x14c718000d58, rawbuf=0x14c718019d20 "INSERT INTO t VALUES (0)", length=24, parser_state=0x14c7780e6a20) at /test/11.8_dbg/sql/sql_parse.cc:7915
      #17 0x000056404d0bfba4 in dispatch_command (command=COM_QUERY, thd=0x14c718000d58, packet=0x14c71800b099 "INSERT INTO t VALUES (0)", packet_length=24, blocking=true) at /test/11.8_dbg/sql/sql_parse.cc:1902
      #18 0x000056404d0c3383 in do_command (thd=0x14c718000d58, blocking=true)at /test/11.8_dbg/sql/sql_parse.cc:1415
      #19 0x000056404d2aca19 in do_handle_one_connection (connect=0x564051da9148, put_in_cache=true) at /test/11.8_dbg/sql/sql_connect.cc:1415
      #20 0x000056404d2ac7be in handle_one_connection (arg=0x564051dc2358)at /test/11.8_dbg/sql/sql_connect.cc:1327
      #21 0x000014c78049ca94 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #22 0x000014c780529c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      CS 11.8.1 33e0796e7a154e02a5e53c55cefc5d6feb4f5e6d (Optimized, UBASAN, Clang) Build 15/02/2025

      /test/11.8_opt_san/sql/sql_statistics.cc:1254:17: runtime error: load of value 4294967295, which is not a valid value for type 'Histogram_type' (aka 'enum_histogram_type')
          #0 0x5603b6f46dac in Column_stat::get_stat_values(Column_statistics*, st_mem_root*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:1254:17
          #1 0x5603b6f20509 in read_statistics_for_table(THD*, TABLE*, TABLE_LIST*, bool, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3096:21
          #2 0x5603b6f20509 in read_statistics_for_tables(THD*, TABLE_LIST*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3354:23
          #3 0x5603b68f336f in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /test/11.8_opt_san/sql/sql_base.cc:5665:12
          #4 0x5603b6a29b2c in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /test/11.8_opt_san/sql/sql_base.h:535:10
          #5 0x5603b6a29b2c in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_opt_san/sql/sql_insert.cc:784:9
          #6 0x5603b6baf307 in mysql_execute_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:4484:10
          #7 0x5603b6b7c600 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_opt_san/sql/sql_parse.cc:7915:18
          #8 0x5603b6b738c6 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_opt_san/sql/sql_parse.cc:1902:7
          #9 0x5603b6b7e8c6 in do_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:1415:17
          #10 0x5603b7204f5c in do_handle_one_connection(CONNECT*, bool) /test/11.8_opt_san/sql/sql_connect.cc:1415:11
          #11 0x5603b72047b6 in handle_one_connection /test/11.8_opt_san/sql/sql_connect.cc:1327:5
          #12 0x5603b65c099c in asan_thread_start(void*) asan_interceptors.cpp.o
          #13 0x145d9f09ca93 in start_thread nptl/pthread_create.c:447:8
          #14 0x145d9f129c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: invalid-enum-load /test/11.8_opt_san/sql/sql_statistics.cc:1254:17 
      /test/11.8_opt_san/sql/sql_statistics.cc:1268:57: runtime error: load of value 4294967295, which is not a valid value for type 'Histogram_type' (aka 'enum_histogram_type')
          #0 0x5603b6f470f9 in Column_stat::get_stat_values(Column_statistics*, st_mem_root*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:1268:57
          #1 0x5603b6f20509 in read_statistics_for_table(THD*, TABLE*, TABLE_LIST*, bool, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3096:21
          #2 0x5603b6f20509 in read_statistics_for_tables(THD*, TABLE_LIST*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3354:23
          #3 0x5603b68f336f in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /test/11.8_opt_san/sql/sql_base.cc:5665:12
          #4 0x5603b6a29b2c in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /test/11.8_opt_san/sql/sql_base.h:535:10
          #5 0x5603b6a29b2c in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_opt_san/sql/sql_insert.cc:784:9
          #6 0x5603b6baf307 in mysql_execute_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:4484:10
          #7 0x5603b6b7c600 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_opt_san/sql/sql_parse.cc:7915:18
          #8 0x5603b6b738c6 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_opt_san/sql/sql_parse.cc:1902:7
          #9 0x5603b6b7e8c6 in do_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:1415:17
          #10 0x5603b7204f5c in do_handle_one_connection(CONNECT*, bool) /test/11.8_opt_san/sql/sql_connect.cc:1415:11
          #11 0x5603b72047b6 in handle_one_connection /test/11.8_opt_san/sql/sql_connect.cc:1327:5
          #12 0x5603b65c099c in asan_thread_start(void*) asan_interceptors.cpp.o
          #13 0x145d9f09ca93 in start_thread nptl/pthread_create.c:447:8
          #14 0x145d9f129c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: invalid-enum-load /test/11.8_opt_san/sql/sql_statistics.cc:1268:57 
      /test/11.8_opt_san/sql/sql_statistics.cc:1719:11: runtime error: load of value 4294967295, which is not a valid value for type 'Histogram_type' (aka 'enum_histogram_type')
          #0 0x5603b6f164fa in create_histogram(st_mem_root*, enum_histogram_type) /test/11.8_opt_san/sql/sql_statistics.cc:1719:11
          #1 0x5603b6f463ad in Column_stat::get_stat_values(Column_statistics*, st_mem_root*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:1268:30
          #2 0x5603b6f20509 in read_statistics_for_table(THD*, TABLE*, TABLE_LIST*, bool, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3096:21
          #3 0x5603b6f20509 in read_statistics_for_tables(THD*, TABLE_LIST*, bool) /test/11.8_opt_san/sql/sql_statistics.cc:3354:23
          #4 0x5603b68f336f in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /test/11.8_opt_san/sql/sql_base.cc:5665:12
          #5 0x5603b6a29b2c in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /test/11.8_opt_san/sql/sql_base.h:535:10
          #6 0x5603b6a29b2c in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_opt_san/sql/sql_insert.cc:784:9
          #7 0x5603b6baf307 in mysql_execute_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:4484:10
          #8 0x5603b6b7c600 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_opt_san/sql/sql_parse.cc:7915:18
          #9 0x5603b6b738c6 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_opt_san/sql/sql_parse.cc:1902:7
          #10 0x5603b6b7e8c6 in do_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:1415:17
          #11 0x5603b7204f5c in do_handle_one_connection(CONNECT*, bool) /test/11.8_opt_san/sql/sql_connect.cc:1415:11
          #12 0x5603b72047b6 in handle_one_connection /test/11.8_opt_san/sql/sql_connect.cc:1327:5
          #13 0x5603b65c099c in asan_thread_start(void*) asan_interceptors.cpp.o
          #14 0x145d9f09ca93 in start_thread nptl/pthread_create.c:447:8
          #15 0x145d9f129c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: invalid-enum-load /test/11.8_opt_san/sql/sql_statistics.cc:1719:11 
      

      Bug confirmed present in:
      MariaDB: 10.11.12 (dbg), 11.4.6 (dbg), 11.8.1 (dbg), 12.0.0 (dbg) and - as UBSAN errors - in 10.11.12 (opt), 11.4.6 (opt), 11.8.1 (opt), 12.0.0 (opt)

      Bug (or feature/syntax) confirmed not present in:
      MariaDB: 10.5.29 (dbg), 10.5.29 (opt), 10.6.22 (dbg), 10.6.22 (opt)

      Testcase is CLI and MTR compatible.

      Attachments

        Activity

          There are no comments yet on this issue.

          People

            psergei Sergei Petrunia
            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.