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

incorrect key in "dup value" error after long unique

    XMLWordPrintable

    Details

      Description

      PoC:

      CREATE TABLE v0 ( v3 FLOAT PRIMARY KEY NULL , v2 TEXT UNIQUE NOT NULL , v1 INT UNIQUE ) ;
       CREATE TABLE v4 ( v6 INT UNIQUE UNIQUE PRIMARY KEY UNIQUE , v5 TEXT , VALUE INT NOT NULL ) ;
       INSERT INTO v0 VALUES ( -32768 , -128 , 58 ) , ( -1 , 44 , -128 ) ;
       INSERT INTO v4 VALUES ( 50 , 61 , -1 ) , ( -2147483648 , -128 , 0 ) ;
       UPDATE v0 AS v0 SET v2 = ( NOT ( ( v1 = 8 OR 'x' = -1 ) IS NULL ) ) , v3 = -128 ;
       UPDATE v0 AS ONE NATURAL JOIN v4 SET v1 = v2 , v5 = 0 ;
       UPDATE v4 NATURAL JOIN v0 VALUE SET v5 = v3 , v1 = 83 ;
       UPDATE v0 SET v2 = 'x' * 'x' , v1 = -1 WHERE v3 IN ( 16 , 36 , NULL , 0 ) ;
      

      report (compiled with ASAN):

      =================================================================
      ==9471==ERROR: AddressSanitizer: heap-use-after-free on address 0x6290000c3288 at pc 0x000002b12085 bp 0x7fe334a243c0 sp 0x7fe334a243b8
      READ of size 1 at 0x6290000c3288 thread T16
          #0 0x2b12084 in my_mb_wc_latin1 /root/mariadb/strings/ctype-latin1.c:376:18
          #1 0x2bd45cb in my_convert_using_func /root/mariadb/strings/ctype.c:1161:18
          #2 0xb5b9b7 in err_conv(char*, unsigned int, char const*, unsigned int, charset_info_st const*) /root/mariadb/sql/sql_error.cc:931:10
          #3 0x1a06285 in ErrBuff::set_str(char const*, unsigned long, charset_info_st const*) const /root/mariadb/sql/sql_error.h:852:10
          #4 0x1a06285 in ErrConvString::lex_cstring() const /root/mariadb/sql/sql_error.h:890:12
          #5 0x1a06285 in field_unpack(String*, Field*, unsigned char const*, unsigned int, bool) /root/mariadb/sql/key.cc:396:20
          #6 0x1a06d36 in key_unpack(String*, TABLE*, st_key*) /root/mariadb/sql/key.cc:441:5
          #7 0x15cfdc3 in print_keydup_error(TABLE*, st_key*, char const*, unsigned long) /root/mariadb/sql/handler.cc:4246:5
          #8 0x15d2509 in print_keydup_error(TABLE*, st_key*, unsigned long) /root/mariadb/sql/handler.cc:4269:3
          #9 0x15d2509 in handler::print_error(int, unsigned long) /root/mariadb/sql/handler.cc:4345:9
          #10 0x100e249 in multi_update::send_data(List<Item>&) /root/mariadb/sql/sql_update.cc:2688:18
          #11 0xdb5094 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /root/mariadb/sql/sql_class.h:5612:12
          #12 0xdb5094 in end_send(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:22331:9
          #13 0xe315ff in evaluate_join_record(JOIN*, st_join_table*, int) /root/mariadb/sql/sql_select.cc:21325:11
          #14 0xd4c13a in sub_select(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:21095:9
          #15 0xe315ff in evaluate_join_record(JOIN*, st_join_table*, int) /root/mariadb/sql/sql_select.cc:21325:11
          #16 0xd4c13a in sub_select(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:21095:9
          #17 0xdc6797 in do_select(JOIN*, Procedure*) /root/mariadb/sql/sql_select.cc:20640:14
          #18 0xdc6797 in JOIN::exec_inner() /root/mariadb/sql/sql_select.cc:4749:50
          #19 0xdc344c in JOIN::exec() /root/mariadb/sql/sql_select.cc:4527:3
          #20 0xd4e4e8 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*) /root/mariadb/sql/sql_select.cc:5007:9
          #21 0x1006042 in mysql_multi_update(THD*, TABLE_LIST*, List<Item>*, List<Item>*, Item*, unsigned long long, enum_duplicates, bool, st_select_lex_unit*, st_select_lex*, multi_update**) /root/mariadb/sql/sql_update.cc:1968:8
          #22 0xc682e9 in mysql_execute_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:4486:12
          #23 0xc4a67e in mysql_parse(THD*, char*, unsigned int, Parser_state*) /root/mariadb/sql/sql_parse.cc:8027:18
          #24 0xc41ba9 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /root/mariadb/sql/sql_parse.cc:1894:7
          #25 0xc4b74b in do_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:1402:17
          #26 0x111f9f2 in do_handle_one_connection(CONNECT*, bool) /root/mariadb/sql/sql_connect.cc:1418:11
          #27 0x111f248 in handle_one_connection /root/mariadb/sql/sql_connect.cc:1312:5
          #28 0x1f3f9dd in pfs_spawn_thread /root/mariadb/storage/perfschema/pfs.cc:2201:3
          #29 0x7fe35a9ff608 in start_thread /build/glibc-sMfBJT/glibc-2.31/nptl/pthread_create.c:477:8
          #30 0x7fe35a715162 in clone /build/glibc-sMfBJT/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
       
      0x6290000c3288 is located 136 bytes inside of 16512-byte region [0x6290000c3200,0x6290000c7280)
      freed by thread T16 here:
          #0 0x80f732 in free (/usr/local/mysql/bin/mariadbd+0x80f732)
          #1 0x243e1b8 in mem_heap_free(mem_block_info_t*) /root/mariadb/storage/innobase/include/mem0mem.inl:419:3
          #2 0x243e1b8 in row_mysql_prebuilt_free_blob_heap(row_prebuilt_t*) /root/mariadb/storage/innobase/row/row0mysql.cc:101:2
          #3 0x24b554c in row_sel_store_mysql_rec(unsigned char*, row_prebuilt_t*, unsigned char const*, dtuple_t const*, bool, dict_index_t const*, unsigned short const*) /root/mariadb/storage/innobase/row/row0sel.cc:3109:3
          #4 0x24afa37 in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /root/mariadb/storage/innobase/row/row0sel.cc:5656:9
          #5 0x21739c3 in ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function) /root/mariadb/storage/innobase/handler/ha_innodb.cc:8970:5
          #6 0x15c539a in handler::ha_rnd_pos(unsigned char*, unsigned char*) /root/mariadb/sql/handler.cc:3425:3
          #7 0x1002a33 in prepare_record_for_error_message(int, TABLE*) /root/mariadb/sql/sql_update.cc:304:23
          #8 0x100e1fd in multi_update::send_data(List<Item>&) /root/mariadb/sql/sql_update.cc:2687:5
          #9 0xdb5094 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /root/mariadb/sql/sql_class.h:5612:12
          #10 0xdb5094 in end_send(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:22331:9
          #11 0xe315ff in evaluate_join_record(JOIN*, st_join_table*, int) /root/mariadb/sql/sql_select.cc:21325:11
          #12 0xd4c13a in sub_select(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:21095:9
          #13 0xe315ff in evaluate_join_record(JOIN*, st_join_table*, int) /root/mariadb/sql/sql_select.cc:21325:11
          #14 0xd4c13a in sub_select(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:21095:9
          #15 0xdc6797 in do_select(JOIN*, Procedure*) /root/mariadb/sql/sql_select.cc:20640:14
          #16 0xdc6797 in JOIN::exec_inner() /root/mariadb/sql/sql_select.cc:4749:50
          #17 0xdc344c in JOIN::exec() /root/mariadb/sql/sql_select.cc:4527:3
          #18 0xd4e4e8 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*) /root/mariadb/sql/sql_select.cc:5007:9
          #19 0x1006042 in mysql_multi_update(THD*, TABLE_LIST*, List<Item>*, List<Item>*, Item*, unsigned long long, enum_duplicates, bool, st_select_lex_unit*, st_select_lex*, multi_update**) /root/mariadb/sql/sql_update.cc:1968:8
          #20 0xc682e9 in mysql_execute_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:4486:12
          #21 0xc4a67e in mysql_parse(THD*, char*, unsigned int, Parser_state*) /root/mariadb/sql/sql_parse.cc:8027:18
          #22 0xc41ba9 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /root/mariadb/sql/sql_parse.cc:1894:7
          #23 0xc4b74b in do_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:1402:17
          #24 0x111f9f2 in do_handle_one_connection(CONNECT*, bool) /root/mariadb/sql/sql_connect.cc:1418:11
          #25 0x111f248 in handle_one_connection /root/mariadb/sql/sql_connect.cc:1312:5
          #26 0x1f3f9dd in pfs_spawn_thread /root/mariadb/storage/perfschema/pfs.cc:2201:3
          #27 0x7fe35a9ff608 in start_thread /build/glibc-sMfBJT/glibc-2.31/nptl/pthread_create.c:477:8
       
      previously allocated by thread T16 here:
          #0 0x80f99d in malloc (/usr/local/mysql/bin/mariadbd+0x80f99d)
          #1 0x215c51e in ut_allocator<unsigned char, true>::allocate(unsigned long, unsigned char const*, unsigned int, bool, bool) /root/mariadb/storage/innobase/include/ut0new.h:375:11
          #2 0x2301754 in mem_heap_create_block_func(mem_block_info_t*, unsigned long, unsigned long) /root/mariadb/storage/innobase/mem/mem0mem.cc:277:37
          #3 0x24be2fc in mem_heap_create_func(unsigned long, unsigned long) /root/mariadb/storage/innobase/include/mem0mem.inl:377:10
          #4 0x24be2fc in row_sel_store_mysql_field(unsigned char*, row_prebuilt_t*, unsigned char const*, dict_index_t const*, unsigned short const*, unsigned long, mysql_row_templ_t const*) /root/mariadb/storage/innobase/row/row0sel.cc:3050:27
          #5 0x24b4ea9 in row_sel_store_mysql_rec(unsigned char*, row_prebuilt_t*, unsigned char const*, dtuple_t const*, bool, dict_index_t const*, unsigned short const*) /root/mariadb/storage/innobase/row/row0sel.cc:3196:8
          #6 0x24afa37 in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /root/mariadb/storage/innobase/row/row0sel.cc:5656:9
          #7 0x21739c3 in ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function) /root/mariadb/storage/innobase/handler/ha_innodb.cc:8970:5
          #8 0x2174d99 in ha_innobase::index_first(unsigned char*) /root/mariadb/storage/innobase/handler/ha_innodb.cc:9339:14
          #9 0x2174d99 in ha_innobase::rnd_next(unsigned char*) /root/mariadb/storage/innobase/handler/ha_innodb.cc:9432:11
          #10 0x15c44c3 in handler::ha_rnd_next(unsigned char*) /root/mariadb/sql/handler.cc:3393:5
          #11 0x930064 in rr_sequential(READ_RECORD*) /root/mariadb/sql/records.cc:519:35
          #12 0xd4c04d in sub_select(JOIN*, st_join_table*, bool) /root/mariadb/sql/sql_select.cc:21092:12
          #13 0xdc6797 in do_select(JOIN*, Procedure*) /root/mariadb/sql/sql_select.cc:20640:14
          #14 0xdc6797 in JOIN::exec_inner() /root/mariadb/sql/sql_select.cc:4749:50
          #15 0xdc344c in JOIN::exec() /root/mariadb/sql/sql_select.cc:4527:3
          #16 0xd4e4e8 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*) /root/mariadb/sql/sql_select.cc:5007:9
          #17 0x1006042 in mysql_multi_update(THD*, TABLE_LIST*, List<Item>*, List<Item>*, Item*, unsigned long long, enum_duplicates, bool, st_select_lex_unit*, st_select_lex*, multi_update**) /root/mariadb/sql/sql_update.cc:1968:8
          #18 0xc682e9 in mysql_execute_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:4486:12
          #19 0xc4a67e in mysql_parse(THD*, char*, unsigned int, Parser_state*) /root/mariadb/sql/sql_parse.cc:8027:18
          #20 0xc41ba9 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /root/mariadb/sql/sql_parse.cc:1894:7
          #21 0xc4b74b in do_command(THD*, bool) /root/mariadb/sql/sql_parse.cc:1402:17
          #22 0x111f9f2 in do_handle_one_connection(CONNECT*, bool) /root/mariadb/sql/sql_connect.cc:1418:11
          #23 0x111f248 in handle_one_connection /root/mariadb/sql/sql_connect.cc:1312:5
          #24 0x1f3f9dd in pfs_spawn_thread /root/mariadb/storage/perfschema/pfs.cc:2201:3
          #25 0x7fe35a9ff608 in start_thread /build/glibc-sMfBJT/glibc-2.31/nptl/pthread_create.c:477:8
       
      Thread T16 created by T0 here:
          #0 0x7f9cfc in pthread_create (/usr/local/mysql/bin/mariadbd+0x7f9cfc)
          #1 0x1f3fd39 in my_thread_create(unsigned long*, pthread_attr_t const*, void* (*)(void*), void*) /root/mariadb/storage/perfschema/my_thread.h:52:10
          #2 0x1f3fd39 in pfs_spawn_thread_v1 /root/mariadb/storage/perfschema/pfs.cc:2252:15
          #3 0x85cef4 in inline_mysql_thread_create(unsigned int, unsigned long*, pthread_attr_t const*, void* (*)(void*), void*) /root/mariadb/include/mysql/psi/mysql_thread.h:1139:11
          #4 0x85cef4 in create_thread_to_handle_connection(CONNECT*) /root/mariadb/sql/mysqld.cc:5975:19
          #5 0x85e72a in create_new_thread(CONNECT*) /root/mariadb/sql/mysqld.cc:6034:3
          #6 0x85e72a in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /root/mariadb/sql/mysqld.cc:6096:5
          #7 0x85a34c in handle_connections_sockets() /root/mariadb/sql/mysqld.cc:6220:9
          #8 0x84e9ef in mysqld_main(int, char**) /root/mariadb/sql/mysqld.cc:5870:3
          #9 0x7fe35a61a0b2 in __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:308:16
       
      SUMMARY: AddressSanitizer: heap-use-after-free /root/mariadb/strings/ctype-latin1.c:376:18 in my_mb_wc_latin1
      Shadow bytes around the buggy address:
        0x0c5280010600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c5280010610: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c5280010620: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c5280010630: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c5280010640: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c5280010650: fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c5280010660: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c5280010670: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c5280010680: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c5280010690: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c52800106a0: 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
      ==9471==ABORTING
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              serg Sergei Golubchik
              Reporter:
              fuboat Jingzhou Fu
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.