Skip to content

Commit b260903

Browse files
committed
MDEV-29258 Failing assertion for name length on RENAME TABLE
trx_undo_page_report_rename(): Use the correct maximum length of a table name. Both the database name and the table name can be up to NAME_CHAR_LEN (64 characters) times 5 bytes per character in the my_charset_filename encoding. They are not encoded in UTF-8! fil_op_write_log(): Reserve the correct amount of log buffer for a rename operation. The file name will be appended by mlog_catenate_string(). rename_file_ext(): Reserve a large enough buffer for the file names.
1 parent 0d1de5e commit b260903

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

mysql-test/suite/innodb/r/foreign_key_not_windows.result

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ CREATE TABLE `d255`.`_##################################################`
1111
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023/_@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023
1212
CREATE TABLE `d255`.`##################################################`
1313
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
14+
#
15+
# MDEV-29258 Failing assertion for name length on RENAME TABLE
16+
#
17+
CREATE TABLE `d255`.`d245` (x INT) ENGINE=InnoDB;
18+
DROP TABLE `d255`.`d250`;
19+
RENAME TABLE `d250#`.`d245` TO `d250#`.`d250`;
20+
RENAME TABLE `d255`.`d250` TO a;
1421
DROP DATABASE `d255`;
15-
DROP TABLE t;
22+
DROP TABLE a,t;
1623
# End of 10.3 tests

mysql-test/suite/innodb/t/foreign_key_not_windows.test

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,23 @@ eval CREATE TABLE `$d255`.`_$d250`
3838
--replace_result $d255 d255
3939
eval CREATE TABLE `$d255`.`$d250`
4040
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
41+
42+
--echo #
43+
--echo # MDEV-29258 Failing assertion for name length on RENAME TABLE
44+
--echo #
45+
46+
let $d245=-------------------------------------------------;
47+
--replace_result $d245 d245 $d255 d255
48+
eval CREATE TABLE `$d255`.`$d245` (x INT) ENGINE=InnoDB;
49+
--replace_result $d250 d250 $d255 d255
50+
eval DROP TABLE `$d255`.`$d250`;
51+
52+
--replace_result $d245 d245 $d250 d250 d255 d255
53+
eval RENAME TABLE `$d255`.`$d245` TO `$d255`.`$d250`;
54+
--replace_result $d250 d250 $d255 d255
55+
eval RENAME TABLE `$d255`.`$d250` TO a;
4156
--replace_result $d255 d255
4257
eval DROP DATABASE `$d255`;
43-
DROP TABLE t;
58+
DROP TABLE a,t;
4459

4560
--echo # End of 10.3 tests

sql/table.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
2-
Copyright (c) 2008, 2021, MariaDB
2+
Copyright (c) 2008, 2022, MariaDB
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -4197,7 +4197,8 @@ void update_create_info_from_table(HA_CREATE_INFO *create_info, TABLE *table)
41974197
int
41984198
rename_file_ext(const char * from,const char * to,const char * ext)
41994199
{
4200-
char from_b[FN_REFLEN],to_b[FN_REFLEN];
4200+
/* Reserve space for ./databasename/tablename.frm + NUL byte */
4201+
char from_b[2 + FN_REFLEN + 4 + 1], to_b[2 + FN_REFLEN + 4 + 1];
42014202
(void) strxmov(from_b,from,ext,NullS);
42024203
(void) strxmov(to_b,to,ext,NullS);
42034204
return mysql_file_rename(key_file_frm, from_b, to_b, MYF(0));

storage/innobase/fil/fil0fil.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ fil_op_write_log(
21052105
case MLOG_FILE_RENAME2:
21062106
ut_ad(strchr(new_path, OS_PATH_SEPARATOR) != NULL);
21072107
len = strlen(new_path) + 1;
2108-
log_ptr = mlog_open(mtr, 2 + len);
2108+
log_ptr = mlog_open(mtr, 2);
21092109
ut_a(log_ptr);
21102110
mach_write_to_2(log_ptr, len);
21112111
log_ptr += 2;

storage/innobase/trx/trx0rec.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2021, MariaDB Corporation.
4+
Copyright (c) 2017, 2022, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -1867,9 +1867,9 @@ trx_undo_page_report_rename(trx_t* trx, const dict_table_t* table,
18671867
byte* start = block->frame + first_free;
18681868
size_t len = strlen(table->name.m_name);
18691869
const size_t fixed = 2 + 1 + 11 + 11 + 2;
1870-
ut_ad(len <= NAME_LEN * 2 + 1);
1870+
ut_ad(len <= NAME_CHAR_LEN * 5 * 2 + 1);
18711871
/* The -10 is used in trx_undo_left() */
1872-
compile_time_assert((NAME_LEN * 1) * 2 + fixed
1872+
compile_time_assert(NAME_CHAR_LEN * 5 * 2 + fixed
18731873
+ TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE
18741874
< UNIV_PAGE_SIZE_MIN - 10 - FIL_PAGE_DATA_END);
18751875

0 commit comments

Comments
 (0)