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

JSON_TABLE: ASAN use-after-poison in field_conv_memcpy / Create_tmp_table::finalize upon query with derived table

    XMLWordPrintable

Details

    Description

      Maybe the root cause is outside JSON_TABLE, but I couldn't modify the test case to avoid using it.

      SET NAMES utf8;
      SELECT * FROM ( SELECT * FROM JSON_TABLE('{}', '$' COLUMNS( a BINARY(12) PATH '$.*', b VARCHAR(40) PATH '$[*]', c VARCHAR(8) PATH '$**.*')) AS jt ) AS sq;
      

      bb-10.6-mdev17399-hf 3530463bc

      ==3817918==ERROR: AddressSanitizer: use-after-poison on address 0x61900008abd0 at pc 0x7f05e2e03480 bp 0x7f05d9245600 sp 0x7f05d9244da8
      READ of size 121 at 0x61900008abd0 thread T5
          #0 0x7f05e2e0347f  (/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f)
          #1 0x557a1a83b7e5 in field_conv_memcpy /data/src/bb-10.6-mdev17399-hf/sql/field_conv.cc:832
          #2 0x557a1a83b8eb in field_conv(Field*, Field*) /data/src/bb-10.6-mdev17399-hf/sql/field_conv.cc:862
          #3 0x557a1a18f2f1 in Create_tmp_table::finalize(THD*, TABLE*, TMP_TABLE_PARAM*, bool, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_select.cc:18946
          #4 0x557a1a1948fa in create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long long, unsigned long long, st_mysql_const_lex_string const*, bool, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_select.cc:19322
          #5 0x557a1a3366e1 in select_unit::create_result_table(THD*, List<Item>*, bool, unsigned long long, st_mysql_const_lex_string const*, bool, bool, bool, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/sql_union.cc:329
          #6 0x557a19f732da in mysql_derived_prepare /data/src/bb-10.6-mdev17399-hf/sql/sql_derived.cc:846
          #7 0x557a19f6f22f in mysql_handle_single_derived(LEX*, TABLE_LIST*, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/sql_derived.cc:206
          #8 0x557a1a3ccd2a in TABLE_LIST::handle_derived(LEX*, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/table.cc:9205
          #9 0x557a19fb7db1 in LEX::handle_list_of_derived(TABLE_LIST*, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/sql_lex.h:4433
          #10 0x557a19fde256 in st_select_lex::handle_derived(LEX*, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/sql_lex.cc:4944
          #11 0x557a1a1034ab in JOIN::prepare(TABLE_LIST*, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /data/src/bb-10.6-mdev17399-hf/sql/sql_select.cc:1158
          #12 0x557a1a12a222 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*) /data/src/bb-10.6-mdev17399-hf/sql/sql_select.cc:4723
          #13 0x557a1a1d2ac8 in mysql_explain_union(THD*, st_select_lex_unit*, select_result*) /data/src/bb-10.6-mdev17399-hf/sql/sql_select.cc:27378
          #14 0x557a1a065110 in execute_sqlcom_select /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:6169
          #15 0x557a1a054ca3 in mysql_execute_command(THD*) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:3926
          #16 0x557a1a070c6c in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:8000
          #17 0x557a1a0476a7 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:1886
          #18 0x557a1a0443e2 in do_command(THD*, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:1397
          #19 0x557a1a485e84 in do_handle_one_connection(CONNECT*, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_connect.cc:1410
          #20 0x557a1a4857e1 in handle_one_connection /data/src/bb-10.6-mdev17399-hf/sql/sql_connect.cc:1312
          #21 0x557a1b19008a in pfs_spawn_thread /data/src/bb-10.6-mdev17399-hf/storage/perfschema/pfs.cc:2201
          #22 0x7f05e2925608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
          #23 0x7f05e24f9292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
       
      0x61900008abe4 is located 0 bytes to the right of 1124-byte region [0x61900008a780,0x61900008abe4)
      allocated by thread T5 here:
          #0 0x7f05e2e75bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
          #1 0x557a1bdc77e3 in sf_malloc /data/src/bb-10.6-mdev17399-hf/mysys/safemalloc.c:121
          #2 0x557a1bd9432b in my_malloc /data/src/bb-10.6-mdev17399-hf/mysys/my_malloc.c:90
          #3 0x557a1bd7032b in alloc_root /data/src/bb-10.6-mdev17399-hf/mysys/my_alloc.c:244
          #4 0x557a1a1e4e00 in Field::operator new(unsigned long, st_mem_root*) /data/src/bb-10.6-mdev17399-hf/sql/field.h:761
          #5 0x557a1a61a12d in Type_handler_string::make_table_field_from_def(TABLE_SHARE*, st_mem_root*, st_mysql_const_lex_string const*, Record_addr const&, Bit_addr const&, Column_definition_attributes const*, unsigned int) const /data/src/bb-10.6-mdev17399-hf/sql/sql_type.cc:8250
          #6 0x557a1a6b528a in Create_json_table::add_json_table_fields(THD*, TABLE*, Table_function_json_table*) /data/src/bb-10.6-mdev17399-hf/sql/json_table.cc:845
          #7 0x557a1a6b5b23 in create_table_for_function(THD*, TABLE_LIST*) /data/src/bb-10.6-mdev17399-hf/sql/json_table.cc:900
          #8 0x557a19ebb4b0 in open_and_process_table /data/src/bb-10.6-mdev17399-hf/sql/sql_base.cc:3690
          #9 0x557a19ebec8b in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) /data/src/bb-10.6-mdev17399-hf/sql/sql_base.cc:4283
          #10 0x557a19ec3b5f in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /data/src/bb-10.6-mdev17399-hf/sql/sql_base.cc:5241
          #11 0x557a19e1bb9b in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /data/src/bb-10.6-mdev17399-hf/sql/sql_base.h:507
          #12 0x557a1a064f40 in execute_sqlcom_select /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:6151
          #13 0x557a1a054ca3 in mysql_execute_command(THD*) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:3926
          #14 0x557a1a070c6c in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:8000
          #15 0x557a1a0476a7 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:1886
          #16 0x557a1a0443e2 in do_command(THD*, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_parse.cc:1397
          #17 0x557a1a485e84 in do_handle_one_connection(CONNECT*, bool) /data/src/bb-10.6-mdev17399-hf/sql/sql_connect.cc:1410
          #18 0x557a1a4857e1 in handle_one_connection /data/src/bb-10.6-mdev17399-hf/sql/sql_connect.cc:1312
          #19 0x557a1b19008a in pfs_spawn_thread /data/src/bb-10.6-mdev17399-hf/storage/perfschema/pfs.cc:2201
          #20 0x7f05e2925608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
       
      Thread T5 created by T0 here:
          #0 0x7f05e2da2805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
          #1 0x557a1b18b02e in my_thread_create /data/src/bb-10.6-mdev17399-hf/storage/perfschema/my_thread.h:38
          #2 0x557a1b19047d in pfs_spawn_thread_v1 /data/src/bb-10.6-mdev17399-hf/storage/perfschema/pfs.cc:2252
          #3 0x557a19d35bd8 in inline_mysql_thread_create /data/src/bb-10.6-mdev17399-hf/include/mysql/psi/mysql_thread.h:1139
          #4 0x557a19d4bb73 in create_thread_to_handle_connection(CONNECT*) /data/src/bb-10.6-mdev17399-hf/sql/mysqld.cc:5780
          #5 0x557a19d4c1f2 in create_new_thread(CONNECT*) /data/src/bb-10.6-mdev17399-hf/sql/mysqld.cc:5839
          #6 0x557a19d4c55f in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/bb-10.6-mdev17399-hf/sql/mysqld.cc:5901
          #7 0x557a19d4cf0c in handle_connections_sockets() /data/src/bb-10.6-mdev17399-hf/sql/mysqld.cc:6023
          #8 0x557a19d4b380 in mysqld_main(int, char**) /data/src/bb-10.6-mdev17399-hf/sql/mysqld.cc:5675
          #9 0x557a19d34efc in main /data/src/bb-10.6-mdev17399-hf/sql/main.cc:25
          #10 0x7f05e23fe0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
       
      SUMMARY: AddressSanitizer: use-after-poison (/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f) 
      Shadow bytes around the buggy address:
        0x0c3280009520: 00 00 f7 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c3280009530: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c3280009540: f7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c3280009550: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f7 00
        0x0c3280009560: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      =>0x0c3280009570: 00 00 00 00 00 00 00 00 00 00[f7]f7 04 fa fa fa
        0x0c3280009580: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c3280009590: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c32800095a0: 00 00 00 00 f7 00 00 00 00 f7 f7 f7 f7 f7 f7 f7
        0x0c32800095b0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c32800095c0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
      Shadow byte legend (one shadow byte represents 8 application bytes):
        Addressable:           00
        Partially addressable: 01 02 03 04 05 06 07 
        Heap left redzone:       fa
        Freed heap region:       fd
        Stack left redzone:      f1
        Stack mid redzone:       f2
        Stack right redzone:     f3
        Stack after return:      f5
        Stack use after scope:   f8
        Global redzone:          f9
        Global init order:       f6
        Poisoned by user:        f7
        Container overflow:      fc
        Array cookie:            ac
        Intra object redzone:    bb
        ASan internal:           fe
        Left alloca redzone:     ca
        Right alloca redzone:    cb
        Shadow gap:              cc
      ==3817918==ABORTING
      210318 19:14:47 [ERROR] mysqld got signal 6 ;
      This could be because you hit a bug. It is also possible that this binary
      or one of the libraries it was linked against is corrupt, improperly built,
      or misconfigured. This error can also be caused by malfunctioning hardware.
       
      To report this bug, see https://mariadb.com/kb/en/reporting-bugs
       
      We will try our best to scrape up some info that will hopefully help
      diagnose the problem, but since we have already crashed, 
      something is definitely wrong and this may fail.
       
      Server version: 10.6.0-MariaDB-debug-log
      key_buffer_size=1048576
      read_buffer_size=131072
      max_used_connections=1
      max_threads=153
      thread_count=1
      It is possible that mysqld could use up to 
      key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 63804 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x62b000069288
      Attempting backtrace. You can use the following information to find out
      where mysqld died. If you see no messages after this, something went
      terribly wrong...
      stack_bottom = 0x7f05d9249950 thread_stack 0x5fc00
      ??:0(__interceptor_tcgetattr)[0x7f05e2dd4d30]
      mysys/stacktrace.c:212(my_print_stacktrace)[0x557a1bda5dd7]
      sql/signal_handler.cc:212(handle_fatal_signal)[0x557a1a8597c1]
      sigaction.c:0(__restore_rt)[0x7f05e29313c0]
      ??:0(gsignal)[0x7f05e241d18b]
      ??:0(abort)[0x7f05e23fc859]
      ??:0(__sanitizer_set_report_fd)[0x7f05e2e936a2]
      ??:0(__sanitizer_get_module_and_offset_for_pc)[0x7f05e2e9e24c]
      ??:0(__sanitizer_ptr_cmp)[0x7f05e2e7f8ec]
      ??:0(__asan_on_error)[0x7f05e2e7f363]
      ??:0(__interceptor_getdelim)[0x7f05e2e0349f]
      sql/field_conv.cc:833(field_conv_memcpy(Field*, Field*))[0x557a1a83b7e6]
      sql/field_conv.cc:863(field_conv(Field*, Field*))[0x557a1a83b8ec]
      sql/sql_select.cc:18947(Create_tmp_table::finalize(THD*, TABLE*, TMP_TABLE_PARAM*, bool, bool))[0x557a1a18f2f2]
      sql/sql_select.cc:19321(create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long long, unsigned long long, st_mysql_const_lex_string const*, bool, bool))[0x557a1a1948fb]
      sql/sql_union.cc:329(select_unit::create_result_table(THD*, List<Item>*, bool, unsigned long long, st_mysql_const_lex_string const*, bool, bool, bool, unsigned int))[0x557a1a3366e2]
      sql/sql_derived.cc:846(mysql_derived_prepare(THD*, LEX*, TABLE_LIST*))[0x557a19f732db]
      sql/sql_derived.cc:206(mysql_handle_single_derived(LEX*, TABLE_LIST*, unsigned int))[0x557a19f6f230]
      sql/table.cc:9205(TABLE_LIST::handle_derived(LEX*, unsigned int))[0x557a1a3ccd2b]
      sql/sql_lex.h:4433(LEX::handle_list_of_derived(TABLE_LIST*, unsigned int))[0x557a19fb7db2]
      sql/sql_lex.cc:4945(st_select_lex::handle_derived(LEX*, unsigned int))[0x557a19fde257]
      sql/sql_select.cc:1158(JOIN::prepare(TABLE_LIST*, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*))[0x557a1a1034ac]
      sql/sql_select.cc:4723(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*))[0x557a1a12a223]
      sql/sql_select.cc:27378(mysql_explain_union(THD*, st_select_lex_unit*, select_result*))[0x557a1a1d2ac9]
      sql/sql_parse.cc:6169(execute_sqlcom_select(THD*, TABLE_LIST*))[0x557a1a065111]
      sql/sql_parse.cc:3926(mysql_execute_command(THD*))[0x557a1a054ca4]
      sql/sql_parse.cc:8000(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x557a1a070c6d]
      sql/sql_parse.cc:1888(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x557a1a0476a8]
      sql/sql_parse.cc:1397(do_command(THD*, bool))[0x557a1a0443e3]
      sql/sql_connect.cc:1410(do_handle_one_connection(CONNECT*, bool))[0x557a1a485e85]
      sql/sql_connect.cc:1314(handle_one_connection)[0x557a1a4857e2]
      perfschema/pfs.cc:2203(pfs_spawn_thread)[0x557a1b19008b]
      nptl/pthread_create.c:478(start_thread)[0x7f05e2925609]
      ??:0(clone)[0x7f05e24f9293]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x62b0000382a8): explain extended SELECT * FROM ( SELECT * FROM JSON_TABLE('{}', '$' COLUMNS( a BINARY(12) PATH '$.*', b VARCHAR(40) PATH '$[*]', c VARCHAR(8) PATH '$**.*')) AS jt ) AS sq
       
      Connection ID (thread ID): 4
      Status: NOT_KILLED
       
      Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
       
      The manual page at https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mysqld/ contains
      information that should help you find out what is causing the crash.
      Writing a core file...
      Working directory at /dev/shm/var_auto_wfJT/mysqld.1/data
      Resource Limits:
      Limit                     Soft Limit           Hard Limit           Units     
      Max cpu time              unlimited            unlimited            seconds   
      Max file size             unlimited            unlimited            bytes     
      Max data size             unlimited            unlimited            bytes     
      Max stack size            8388608              unlimited            bytes     
      Max core file size        unlimited            unlimited            bytes     
      Max resident set          unlimited            unlimited            bytes     
      Max processes             385874               385874               processes 
      Max open files            1024                 1024                 files     
      Max locked memory         67108864             67108864             bytes     
      Max address space         unlimited            unlimited            bytes     
      Max file locks            unlimited            unlimited            locks     
      Max pending signals       385874               385874               signals   
      Max msgqueue size         819200               819200               bytes     
      Max nice priority         0                    0                    
      Max realtime priority     0                    0                    
      Max realtime timeout      unlimited            unlimited            us        
      Core pattern: |/usr/share/apport/apport %p %s %c %d %P %E
      

      Attachments

        Issue Links

          Activity

            People

              holyfoot Alexey Botchkov
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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