[MDEV-29018] AddressSanitizer errors in ha_spider::field_exchange with UNION on partitioned table Created: 2022-07-03  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Partitioning, Storage Engine - Spider
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Yuchen Pei
Resolution: Unresolved Votes: 0
Labels: ASAN, memory_corruption


 Description   

--source plugin/spider/spider/include/init_spider.inc
--source include/have_partition.inc
 
SET spider_same_server_link= on;
eval create server s foreign data wrapper mysql options (host "127.0.0.1", database "test", user "root", port $MASTER_MYPORT);
 
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
CREATE TABLE t2 (a INT);
INSERT INTO t2 VALUES (3),(4);
 
CREATE TABLE t_spider (a INT) ENGINE=SPIDER PARTITION BY HASH(a) (
  PARTITION p1 COMMENT = "wrapper 'mysql', srv 's', table 't1'",
  PARTITION p2 COMMENT = "wrapper 'mysql', srv 's', table 't2'"  
);
 
SELECT DISTINCT a FROM t_spider UNION SELECT a FROM t_spider;
 
# Cleanup
DROP TABLE t_spider, t1, t2;
 
--source plugin/spider/spider/include/deinit_spider.inc

10.3 be99d0dd

==2666832==ERROR: AddressSanitizer: heap-use-after-free on address 0x6190001edcc8 at pc 0x7f91e6fa8acd bp 0x7f91e7297660 sp 0x7f91e7297658
READ of size 8 at 0x6190001edcc8 thread T5
    #0 0x7f91e6fa8acc in ha_spider::field_exchange(Field*) /data/src/10.3/storage/spider/ha_spider.cc:12199
    #1 0x7f91e6fa9f94 in ha_spider::set_searched_bitmap_from_item_list() /data/src/10.3/storage/spider/ha_spider.cc:12725
    #2 0x7f91e6fab39f in ha_spider::set_select_column_mode() /data/src/10.3/storage/spider/ha_spider.cc:12770
    #3 0x7f91e6fab39f in ha_spider::set_select_column_mode() /data/src/10.3/storage/spider/ha_spider.cc:12733
    #4 0x7f91e6fc5db7 in ha_spider::rnd_init(bool) /data/src/10.3/storage/spider/ha_spider.cc:7545
    #5 0x558e9a7d0450 in handler::ha_rnd_init(bool) /data/src/10.3/sql/handler.h:3059
    #6 0x558e9a7d0450 in ha_partition::rnd_init(bool) /data/src/10.3/sql/ha_partition.cc:5031
    #7 0x558e9983af9b in handler::ha_rnd_init(bool) /data/src/10.3/sql/handler.h:3059
    #8 0x558e9983af9b in handler::ha_rnd_init_with_error(bool) /data/src/10.3/sql/handler.cc:3073
    #9 0x558e99c97c6e in init_read_record(READ_RECORD*, THD*, TABLE*, SQL_SELECT*, SORT_INFO*, int, bool, bool) /data/src/10.3/sql/records.cc:294
    #10 0x558e992e25b0 in join_init_read_record(st_join_table*) /data/src/10.3/sql/sql_select.cc:20834
    #11 0x558e9929a0cf in sub_select(JOIN*, st_join_table*, bool) /data/src/10.3/sql/sql_select.cc:19892
    #12 0x558e9932e14f in do_select /data/src/10.3/sql/sql_select.cc:19433
    #13 0x558e9932e14f in JOIN::exec_inner() /data/src/10.3/sql/sql_select.cc:4151
    #14 0x558e9932f999 in JOIN::exec() /data/src/10.3/sql/sql_select.cc:3945
    #15 0x558e994264fe in st_select_lex_unit::exec() /data/src/10.3/sql/sql_union.cc:1546
    #16 0x558e994323bf in mysql_union(THD*, LEX*, select_result*, st_select_lex_unit*, unsigned long) /data/src/10.3/sql/sql_union.cc:42
    #17 0x558e99332355 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:362
    #18 0x558e991c302f in execute_sqlcom_select /data/src/10.3/sql/sql_parse.cc:6339
    #19 0x558e991e8198 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:3870
    #20 0x558e991f0637 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7870
    #21 0x558e991f5179 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
    #22 0x558e991faf1d in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
    #23 0x558e99518c96 in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
    #24 0x558e995194fa in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
    #25 0x558e9a75ee14 in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
    #26 0x7f91f1cb6ea6 in start_thread nptl/pthread_create.c:477
    #27 0x7f91f1be6dee in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xfddee)
 
0x6190001edcc8 is located 72 bytes inside of 992-byte region [0x6190001edc80,0x6190001ee060)
freed by thread T5 here:
    #0 0x7f91f2558b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123
    #1 0x558e9a81cb7d in free_root /data/src/10.3/mysys/my_alloc.c:430
    #2 0x558e992bf4cb in free_tmp_table(THD*, TABLE*) /data/src/10.3/sql/sql_select.cc:19199
    #3 0x558e9932a864 in JOIN::cleanup(bool) /data/src/10.3/sql/sql_select.cc:13201
    #4 0x558e9932b467 in JOIN::join_free() /data/src/10.3/sql/sql_select.cc:13091
    #5 0x558e9932e01c in do_select /data/src/10.3/sql/sql_select.cc:19480
    #6 0x558e9932e01c in JOIN::exec_inner() /data/src/10.3/sql/sql_select.cc:4151
    #7 0x558e9932f999 in JOIN::exec() /data/src/10.3/sql/sql_select.cc:3945
    #8 0x558e994264fe in st_select_lex_unit::exec() /data/src/10.3/sql/sql_union.cc:1546
    #9 0x558e994323bf in mysql_union(THD*, LEX*, select_result*, st_select_lex_unit*, unsigned long) /data/src/10.3/sql/sql_union.cc:42
    #10 0x558e99332355 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:362
    #11 0x558e991c302f in execute_sqlcom_select /data/src/10.3/sql/sql_parse.cc:6339
    #12 0x558e991e8198 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:3870
    #13 0x558e991f0637 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7870
    #14 0x558e991f5179 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
    #15 0x558e991faf1d in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
    #16 0x558e99518c96 in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
    #17 0x558e995194fa in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
    #18 0x558e9a75ee14 in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
    #19 0x7f91f1cb6ea6 in start_thread nptl/pthread_create.c:477
 
previously allocated by thread T5 here:
    #0 0x7f91f2558e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x558e9a82fe62 in my_malloc /data/src/10.3/mysys/my_malloc.c:101
    #2 0x558e9a81c39b in alloc_root /data/src/10.3/mysys/my_alloc.c:251
    #3 0x558e9a81d155 in memdup_root /data/src/10.3/mysys/my_alloc.c:494
    #4 0x558e997bb30d in Field::make_new_field(st_mem_root*, TABLE*, bool) /data/src/10.3/sql/field.cc:2347
    #5 0x558e992b0efe in create_tmp_field_from_field(THD*, Field*, st_mysql_const_lex_string*, TABLE*, Item_field*) /data/src/10.3/sql/sql_select.cc:17140
    #6 0x558e992b2254 in create_tmp_field(THD*, TABLE*, Item*, Item::Type, Item***, Field**, Field**, bool, bool, bool, bool) /data/src/10.3/sql/sql_select.cc:17427
    #7 0x558e992c2ae3 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/10.3/sql/sql_select.cc:17885
    #8 0x558e992f3e64 in JOIN::create_postjoin_aggr_table(st_join_table*, List<Item>*, st_order*, bool, bool, bool) /data/src/10.3/sql/sql_select.cc:3458
    #9 0x558e992f6b58 in JOIN::make_aggr_tables_info() /data/src/10.3/sql/sql_select.cc:3058
    #10 0x558e993189d1 in JOIN::optimize_stage2() /data/src/10.3/sql/sql_select.cc:2697
    #11 0x558e9932283a in JOIN::optimize_inner() /data/src/10.3/sql/sql_select.cc:2003
    #12 0x558e993297a1 in JOIN::optimize() /data/src/10.3/sql/sql_select.cc:1519
    #13 0x558e99424eb1 in st_select_lex_unit::optimize() /data/src/10.3/sql/sql_union.cc:1434
    #14 0x558e994256f4 in st_select_lex_unit::exec() /data/src/10.3/sql/sql_union.cc:1468
    #15 0x558e994323bf in mysql_union(THD*, LEX*, select_result*, st_select_lex_unit*, unsigned long) /data/src/10.3/sql/sql_union.cc:42
    #16 0x558e99332355 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:362
    #17 0x558e991c302f in execute_sqlcom_select /data/src/10.3/sql/sql_parse.cc:6339
    #18 0x558e991e8198 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:3870
    #19 0x558e991f0637 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7870
    #20 0x558e991f5179 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
    #21 0x558e991faf1d in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
    #22 0x558e99518c96 in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
    #23 0x558e995194fa in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
    #24 0x558e9a75ee14 in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
    #25 0x7f91f1cb6ea6 in start_thread nptl/pthread_create.c:477
 
Thread T5 created by T0 here:
    #0 0x7f91f25042a2 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:214
    #1 0x558e9a76346a in spawn_thread_v1 /data/src/10.3/storage/perfschema/pfs.cc:1919
    #2 0x558e98f87f9b in inline_mysql_thread_create /data/src/10.3/include/mysql/psi/mysql_thread.h:1275
    #3 0x558e98f87f9b in create_thread_to_handle_connection(CONNECT*) /data/src/10.3/sql/mysqld.cc:6668
    #4 0x558e98f982ad in create_new_thread /data/src/10.3/sql/mysqld.cc:6738
    #5 0x558e98f982ad in handle_connections_sockets() /data/src/10.3/sql/mysqld.cc:6996
    #6 0x558e98f9a255 in mysqld_main(int, char**) /data/src/10.3/sql/mysqld.cc:6290
    #7 0x7f91f1b0fd09 in __libc_start_main ../csu/libc-start.c:308
 
SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.3/storage/spider/ha_spider.cc:12199 in ha_spider::field_exchange(Field*)
Shadow bytes around the buggy address:
  0x0c3280035b40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035b50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035b60: fd fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3280035b70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c3280035b80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c3280035b90: fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd
  0x0c3280035ba0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035bb0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035bc0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035bd0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280035be0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
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



 Comments   
Comment by Roel Van de Paar [ 2023-05-20 ]

I ran into this one as well.

--source include/have_innodb.inc
--let $SOCKET= `SELECT @@global.socket`
INSTALL PLUGIN Spider SONAME 'ha_spider.so';
CREATE USER spider@localhost IDENTIFIED BY 'pwd';
GRANT ALL ON test.* TO spider@localhost;
eval CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$SOCKET",DATABASE 'test',USER 'spider',PASSWORD 'pwd');
CREATE TABLE t (c INT KEY) ENGINE=InnoDB;
INSERT INTO t VALUES (0),(1),(2);
CREATE TABLE t2 (c INT KEY) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "srv",TABLE "t"';
SELECT * FROM t2 JOIN (SELECT 1 UNION SELECT 1) a ON 1;

Leads to:

11.0.2 368dd22a816f3b437bccd0b9ff28b9de9b1abf0a (Debug, UBASAN)

==1446187==ERROR: AddressSanitizer: heap-use-after-free on address 0x6190002d46b8 at pc 0x14c4f0487868 bp 0x14c4f130d590 sp 0x14c4f130d580
READ of size 8 at 0x6190002d46b8 thread T32
    #0 0x14c4f0487867 in ha_spider::field_exchange(Field*) /test/11.0_dbg_san/storage/spider/ha_spider.cc:9254
    #1 0x14c4f048bf7e in ha_spider::set_searched_bitmap_from_item_list() /test/11.0_dbg_san/storage/spider/ha_spider.cc:9561
    #2 0x14c4f04923e8 in ha_spider::set_select_column_mode() /test/11.0_dbg_san/storage/spider/ha_spider.cc:9591
    #3 0x14c4f05421db in ha_spider::index_init(unsigned int, bool) /test/11.0_dbg_san/storage/spider/ha_spider.cc:1217
    #4 0x5625c4269406 in handler::ha_index_init(unsigned int, bool) /test/11.0_dbg_san/sql/handler.h:3408
    #5 0x5625c4269406 in init_read_record_idx(READ_RECORD*, THD*, TABLE*, bool, unsigned int, bool) /test/11.0_dbg_san/sql/records.cc:85
    #6 0x5625c4cc874c in join_init_read_record(st_join_table*) /test/11.0_dbg_san/sql/sql_select.cc:24256
    #7 0x5625c5535350 in JOIN_TAB_SCAN::open() /test/11.0_dbg_san/sql/sql_join_cache.cc:3459
    #8 0x5625c555b8c4 in JOIN_CACHE::join_matching_records(bool) /test/11.0_dbg_san/sql/sql_join_cache.cc:2333
    #9 0x5625c5557882 in JOIN_CACHE::join_records(bool) /test/11.0_dbg_san/sql/sql_join_cache.cc:2158
    #10 0x5625c4bfa8e4 in sub_select_cache(JOIN*, st_join_table*, bool) /test/11.0_dbg_san/sql/sql_select.cc:23011
    #11 0x5625c4bf8352 in sub_select(JOIN*, st_join_table*, bool) /test/11.0_dbg_san/sql/sql_select.cc:23186
    #12 0x5625c4da6277 in do_select /test/11.0_dbg_san/sql/sql_select.cc:22782
    #13 0x5625c4da6277 in JOIN::exec_inner() /test/11.0_dbg_san/sql/sql_select.cc:4900
    #14 0x5625c4da7916 in JOIN::exec() /test/11.0_dbg_san/sql/sql_select.cc:4677
    #15 0x5625c4d960c1 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/11.0_dbg_san/sql/sql_select.cc:5158
    #16 0x5625c4d9a51c in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:616
    #17 0x5625c490ca01 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6279
    #18 0x5625c496def5 in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
    #19 0x5625c499d973 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:8014
    #20 0x5625c49ad707 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
    #21 0x5625c49bb542 in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
    #22 0x5625c53908b5 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
    #23 0x5625c5391dd0 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
    #24 0x14c4fce94b42 in start_thread nptl/pthread_create.c:442
    #25 0x14c4fcf269ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)
 
0x6190002d46b8 is located 56 bytes inside of 1040-byte region [0x6190002d4680,0x6190002d4a90)
freed by thread T32 here:
    #0 0x5625c4021fe7 in __interceptor_free (/test/UBASAN_MD120523-mariadb-11.0.2-linux-x86_64-dbg/bin/mariadbd+0x7963fe7)
    #1 0x5625c8739a61 in my_free /test/11.0_dbg_san/mysys/my_malloc.c:213
    #2 0x5625c8718091 in root_free /test/11.0_dbg_san/mysys/my_alloc.c:83
    #3 0x5625c871a4e5 in free_root /test/11.0_dbg_san/mysys/my_alloc.c:513
    #4 0x5625c4c6f8f6 in free_tmp_table(THD*, TABLE*) /test/11.0_dbg_san/sql/sql_select.cc:22532
    #5 0x5625c50ce0df in st_select_lex_unit::cleanup() /test/11.0_dbg_san/sql/sql_union.cc:2646
    #6 0x5625c46beef3 in mysql_derived_fill /test/11.0_dbg_san/sql/sql_derived.cc:1322
    #7 0x5625c46bbccf in mysql_handle_single_derived(LEX*, TABLE_LIST*, unsigned int) /test/11.0_dbg_san/sql/sql_derived.cc:200
    #8 0x5625c4bf59fa in st_join_table::preread_init() /test/11.0_dbg_san/sql/sql_select.cc:15863
    #9 0x5625c4bf842b in sub_select(JOIN*, st_join_table*, bool) /test/11.0_dbg_san/sql/sql_select.cc:23200
    #10 0x5625c4da6164 in do_select /test/11.0_dbg_san/sql/sql_select.cc:22780
    #11 0x5625c4da6164 in JOIN::exec_inner() /test/11.0_dbg_san/sql/sql_select.cc:4900
    #12 0x5625c4da7916 in JOIN::exec() /test/11.0_dbg_san/sql/sql_select.cc:4677
    #13 0x5625c4d960c1 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/11.0_dbg_san/sql/sql_select.cc:5158
    #14 0x5625c4d9a51c in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:616
    #15 0x5625c490ca01 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6279
    #16 0x5625c496def5 in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
    #17 0x5625c499d973 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:8014
    #18 0x5625c49ad707 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
    #19 0x5625c49bb542 in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
    #20 0x5625c53908b5 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
    #21 0x5625c5391dd0 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
    #22 0x14c4fce94b42 in start_thread nptl/pthread_create.c:442
 
previously allocated by thread T32 here:
    #0 0x5625c4022337 in __interceptor_malloc (/test/UBASAN_MD120523-mariadb-11.0.2-linux-x86_64-dbg/bin/mariadbd+0x7964337)
    #1 0x5625c8739703 in my_malloc /test/11.0_dbg_san/mysys/my_malloc.c:91
    #2 0x5625c8717f22 in root_alloc /test/11.0_dbg_san/mysys/my_alloc.c:71
    #3 0x5625c8719372 in alloc_root /test/11.0_dbg_san/mysys/my_alloc.c:337
    #4 0x5625c5842fbf in Field::operator new(unsigned long, st_mem_root*) /test/11.0_dbg_san/sql/field.h:775
    #5 0x5625c5842fbf in Type_handler_long::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 /test/11.0_dbg_san/sql/sql_type.cc:8139
    #6 0x5625c583bc76 in Type_handler_int_result::make_table_field(st_mem_root*, st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE_SHARE*) const /test/11.0_dbg_san/sql/sql_type.cc:3574
    #7 0x5625c58b1602 in Type_handler::make_and_init_table_field(st_mem_root*, st_mysql_const_lex_string const*, Record_addr const&, Type_all_attributes const&, TABLE*) const /test/11.0_dbg_san/sql/sql_type.cc:3559
    #8 0x5625c62537b5 in Item_type_holder::create_tmp_field_ex(st_mem_root*, TABLE*, Tmp_field_src*, Tmp_field_param const*) /test/11.0_dbg_san/sql/item.h:7673
    #9 0x5625c4c531de in create_tmp_field(TABLE*, Item*, Item***, Field**, Field**, bool, bool, bool, bool) /test/11.0_dbg_san/sql/sql_select.cc:20642
    #10 0x5625c4c5dbcd in Create_tmp_table::add_fields(THD*, TABLE*, TMP_TABLE_PARAM*, List<Item>&) /test/11.0_dbg_san/sql/sql_select.cc:21080
    #11 0x5625c4c80dda 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) /test/11.0_dbg_san/sql/sql_select.cc:21739
    #12 0x5625c509b2f6 in select_unit::create_result_table(THD*, List<Item>*, bool, unsigned long long, st_mysql_const_lex_string const*, bool, bool, bool, unsigned int) /test/11.0_dbg_san/sql/sql_union.cc:351
    #13 0x5625c50db3cc in st_select_lex_unit::prepare(TABLE_LIST*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_union.cc:1768
    #14 0x5625c46ca993 in mysql_derived_prepare /test/11.0_dbg_san/sql/sql_derived.cc:840
    #15 0x5625c46bbccf in mysql_handle_single_derived(LEX*, TABLE_LIST*, unsigned int) /test/11.0_dbg_san/sql/sql_derived.cc:200
    #16 0x5625c51fa985 in TABLE_LIST::handle_derived(LEX*, unsigned int) /test/11.0_dbg_san/sql/table.cc:9620
    #17 0x5625c47c3f67 in LEX::handle_list_of_derived(TABLE_LIST*, unsigned int) /test/11.0_dbg_san/sql/sql_lex.h:4510
    #18 0x5625c47c3f67 in st_select_lex::handle_derived(LEX*, unsigned int) /test/11.0_dbg_san/sql/sql_lex.cc:4976
    #19 0x5625c4ce98a1 in JOIN::prepare(TABLE_LIST*, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /test/11.0_dbg_san/sql/sql_select.cc:1398
    #20 0x5625c4d98cfc 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/11.0_dbg_san/sql/sql_select.cc:5133
    #21 0x5625c4d9a51c in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:616
    #22 0x5625c490ca01 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6279
    #23 0x5625c496def5 in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
    #24 0x5625c499d973 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:8014
    #25 0x5625c49ad707 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
    #26 0x5625c49bb542 in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
    #27 0x5625c53908b5 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
    #28 0x5625c5391dd0 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
    #29 0x14c4fce94b42 in start_thread nptl/pthread_create.c:442
 
Thread T32 created by T0 here:
    #0 0x5625c3fc6175 in pthread_create (/test/UBASAN_MD120523-mariadb-11.0.2-linux-x86_64-dbg/bin/mariadbd+0x7908175)
    #1 0x5625c407c98b in create_thread_to_handle_connection(CONNECT*) /test/11.0_dbg_san/sql/mysqld.cc:6129
    #2 0x5625c4089e67 in create_new_thread(CONNECT*) /test/11.0_dbg_san/sql/mysqld.cc:6191
    #3 0x5625c408a6e7 in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /test/11.0_dbg_san/sql/mysqld.cc:6253
    #4 0x5625c408b738 in handle_connections_sockets() /test/11.0_dbg_san/sql/mysqld.cc:6377
    #5 0x5625c4092ee7 in mysqld_main(int, char**) /test/11.0_dbg_san/sql/mysqld.cc:6024
    #6 0x5625c4067eca in main /test/11.0_dbg_san/sql/main.cc:34
    #7 0x14c4fce29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
 
SUMMARY: AddressSanitizer: heap-use-after-free /test/11.0_dbg_san/storage/spider/ha_spider.cc:9254 in ha_spider::field_exchange(Field*)
Shadow bytes around the buggy address:
  0x0c3280052880: 00 00 00 00 00 00 00 f7 00 f7 00 f7 f7 f7 f7 f7
  0x0c3280052890: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c32800528a0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c32800528b0: f7 f7 fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c32800528c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c32800528d0: fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd fd
  0x0c32800528e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c32800528f0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280052900: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280052910: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c3280052920: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
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
==1446187==ABORTING
230520 14:47:00 [ERROR] mysqld got signal 6 ;

Comment by Roel Van de Paar [ 2023-05-20 ]

Note the small difference in stacks:

ASAN|heap-use-after-free|storage/spider/ha_spider.cc|ha_spider::field_exchange|ha_spider::set_searched_bitmap_from_item_list|ha_spider::set_select_column_mode|ha_spider::rnd_init
ASAN|heap-use-after-free|storage/spider/ha_spider.cc|ha_spider::field_exchange|ha_spider::set_searched_bitmap_from_item_list|ha_spider::set_select_column_mode|ha_spider::index_init

The first line is the original one, the second is the one in the comment just above.

Generated at Thu Feb 08 10:05:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.