[MDEV-20358] Table corruption or AddressSanitizer: use-after-poison after failed ALTER Created: 2019-08-15  Updated: 2019-08-21  Resolved: 2019-08-21

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.3.18

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Aleksey Midenkov
Resolution: Won't Fix Votes: 0
Labels: regression

Issue Links:
Problem/Incident
is caused by MDEV-17613 MIN/MAX Optimization (Select tables o... Stalled

 Description   

CREATE TABLE t1 (a INT CHECK (a < 10));
 
--connect (con1,localhost,root,,test)
--error ER_BAD_FIELD_ERROR
ALTER TABLE t1 CHANGE a b INT, ALTER a SET DEFAULT 0;
 
--connection default
ALTER TABLE t1 FORCE;
 
# Cleanup
--disconnect con1
DROP TABLE t1;

10.3 asan c23a5e0e

==30150==ERROR: AddressSanitizer: use-after-poison on address 0x62b00002aa50 at pc 0x55c9370c9eb6 bp 0x7fb682d63620 sp 0x7fb682d63618
READ of size 1 at 0x62b00002aa50 thread T5
    #0 0x55c9370c9eb5 in Item_ident::print(String*, enum_query_type) /data/src/10.3/sql/item.cc:3370
    #1 0x55c9370eb49f in Item_field::print(String*, enum_query_type) /data/src/10.3/sql/item.cc:7730
    #2 0x55c9370b3748 in Item::print_parenthesised(String*, enum_query_type, precedence) /data/src/10.3/sql/item.cc:602
    #3 0x55c93719fe7e in Item_func::print_op(String*, enum_query_type) /data/src/10.3/sql/item_func.cc:609
    #4 0x55c93715a68c in Item_bool_rowready_func2::print(String*, enum_query_type) /data/src/10.3/sql/item_cmpfunc.h:512
    #5 0x55c9370b3748 in Item::print_parenthesised(String*, enum_query_type, precedence) /data/src/10.3/sql/item.cc:602
    #6 0x55c936b62557 in Item::print_for_table_def(String*) /data/src/10.3/sql/item.h:1423
    #7 0x55c936b62cc3 in Virtual_column_info::print(String*) /data/src/10.3/sql/item.h:6573
    #8 0x55c936c89cda in pack_expression /data/src/10.3/sql/unireg.cc:639
    #9 0x55c936c8a0de in pack_vcols /data/src/10.3/sql/unireg.cc:668
    #10 0x55c936c863ba in build_frm_image(THD*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, List<Create_field>&, unsigned int, st_key*, handler*) /data/src/10.3/sql/unireg.cc:194
    #11 0x55c936ba2023 in mysql_create_frm_image(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, Alter_info*, int, st_key**, unsigned int*, st_mysql_const_unsigned_lex_string*) /data/src/10.3/sql/sql_table.cc:4724
    #12 0x55c936ba33d3 in create_table_impl /data/src/10.3/sql/sql_table.cc:4965
    #13 0x55c936bc027c in mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool) /data/src/10.3/sql/sql_table.cc:9700
    #14 0x55c936d0709d in Sql_cmd_alter_table::execute(THD*) /data/src/10.3/sql/sql_alter.cc:500
    #15 0x55c9369adc5a in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:6023
    #16 0x55c9369b8985 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7829
    #17 0x55c9369949d5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1856
    #18 0x55c93699198f in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1401
    #19 0x55c936cf81ba in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
    #20 0x55c936cf7b81 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
    #21 0x55c93808760f in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1862
    #22 0x7fb68e7a04a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
    #23 0x7fb68cce8d0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
 
0x62b00002aa50 is located 2128 bytes inside of 24716-byte region [0x62b00002a200,0x62b00003028c)
allocated by thread T6 here:
    #0 0x7fb68ea77d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
    #1 0x55c9381af4f3 in sf_malloc /data/src/10.3/mysys/safemalloc.c:118
    #2 0x55c938181806 in my_malloc /data/src/10.3/mysys/my_malloc.c:101
    #3 0x55c938161e3e in reset_root_defaults /data/src/10.3/mysys/my_alloc.c:151
    #4 0x55c9368ac8ef in THD::init_for_queries() /data/src/10.3/sql/sql_class.cc:1342
    #5 0x55c936cf7526 in prepare_new_connection_state(THD*) /data/src/10.3/sql/sql_connect.cc:1239
    #6 0x55c936cf7bc7 in thd_prepare_connection(THD*) /data/src/10.3/sql/sql_connect.cc:1323
    #7 0x55c936cf816d in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1393
    #8 0x55c936cf7b81 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
    #9 0x55c93808760f in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1862
    #10 0x7fb68e7a04a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
 
Thread T5 created by T0 here:
    #0 0x7fb68e9e6f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
    #1 0x55c938087a4b in spawn_thread_v1 /data/src/10.3/storage/perfschema/pfs.cc:1912
    #2 0x55c93670d110 in inline_mysql_thread_create /data/src/10.3/include/mysql/psi/mysql_thread.h:1268
    #3 0x55c936722029 in create_thread_to_handle_connection(CONNECT*) /data/src/10.3/sql/mysqld.cc:6608
    #4 0x55c93672270c in create_new_thread /data/src/10.3/sql/mysqld.cc:6678
    #5 0x55c936723724 in handle_connections_sockets() /data/src/10.3/sql/mysqld.cc:6953
    #6 0x55c9367214f9 in mysqld_main(int, char**) /data/src/10.3/sql/mysqld.cc:6230
    #7 0x55c93670b82f in main /data/src/10.3/sql/main.cc:25
    #8 0x7fb68cc202e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
 
Thread T6 created by T0 here:
    #0 0x7fb68e9e6f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
    #1 0x55c938087a4b in spawn_thread_v1 /data/src/10.3/storage/perfschema/pfs.cc:1912
    #2 0x55c93670d110 in inline_mysql_thread_create /data/src/10.3/include/mysql/psi/mysql_thread.h:1268
    #3 0x55c936722029 in create_thread_to_handle_connection(CONNECT*) /data/src/10.3/sql/mysqld.cc:6608
    #4 0x55c93672270c in create_new_thread /data/src/10.3/sql/mysqld.cc:6678
    #5 0x55c936723724 in handle_connections_sockets() /data/src/10.3/sql/mysqld.cc:6953
    #6 0x55c9367214f9 in mysqld_main(int, char**) /data/src/10.3/sql/mysqld.cc:6230
    #7 0x55c93670b82f in main /data/src/10.3/sql/main.cc:25
    #8 0x7fb68cc202e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
 
SUMMARY: AddressSanitizer: use-after-poison /data/src/10.3/sql/item.cc:3370 in Item_ident::print(String*, enum_query_type)
Shadow bytes around the buggy address:
  0x0c567fffd4f0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd500: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd510: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd520: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd530: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
=>0x0c567fffd540: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7[f7]f7 f7 f7 f7 f7
  0x0c567fffd550: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd560: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd570: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd580: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
  0x0c567fffd590: 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  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
==30150==ABORTING

Non-ASAN build returns weird errors indicating corruption:

CURRENT_TEST: bug.3552a
mysqltest: At line 8: query 'ALTER TABLE t1 FORCE' failed: 1300: Invalid utf8mb4 character string: '\x8F'

Table structure also shows either corruption or inconsistency:

SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL CHECK (`b` < 10)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL CHECK (`?` < 10)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

The problem appeared in 10.3 tree with this commit:

commit 22914ec793b850438c77acf070f8441cf307ebf6
Author: Aleksey Midenkov
Date:   Tue Feb 5 00:57:31 2019 +0300
 
    MDEV-18154 Deadlock and assertion upon no-op ALTER under LOCK TABLES
    
    1. Fix DBUG_ASSERT(!table->pos_in_locked_tables) in tc_release_table();
    2. Fix access of prematurely freed MDL_ticket: don't close ticket if table was not closed;
    3. Fix deadlock after erroneous ALTER.
    
    mysql_alter_table() leaves dirty table->m_needs_reopen in case of
    error exit which then incorrectly treated by mysql_lock_tables().



 Comments   
Comment by Aleksey Midenkov [ 2019-08-21 ]

Causing issue was reverted and will be reworked.

Generated at Thu Feb 08 08:58:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.