From 71ee8615c34db5299d51bc440309371ea08b5923 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Feb 2006 18:09:32 +0300 Subject: [PATCH] Fixed bug#17530: Incorrect key truncation on table creation caused server crash. When a too long field is used for a key, only a prefix part of the field is used. Length is reduced to the max key length allowed for storage. But if the field have a multibyte charset it is possible to break multibyte char sequence. This leads to the failed assertion in the innodb code and server crash when a record is inserted. The make_prepare_table() now aligns truncated key length to the boundary of multibyte char. mysql-test/t/create.test: Added test case for bug#17530: Incorrect key truncation on table creation caused server crash. mysql-test/r/create.result: Added test case for bug#17530: Incorrect key truncation on table creation caused server crash. sql/sql_table.cc: Fixed bug#17530: Incorrect key truncation on table creation caused server crash. The make_prepare_table() now aligns truncated key length to the boundary of multibyte char. --- mysql-test/r/create.result | 6 ++++++ mysql-test/t/create.test | 8 ++++++++ sql/sql_table.cc | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 848b84e2b8c..8c1943486b5 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -765,3 +765,9 @@ t1 CREATE TABLE `t1` ( `i` int(11) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 MAX_ROWS=4294967295 drop table t1; +create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb +character set utf8 collate utf8_general_ci; +Warnings: +Warning 1071 Specified key was too long; max key length is 765 bytes +insert into t1 values('aaa'); +drop table t1; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index f7b9002faa0..9fcbb53e24d 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -660,4 +660,12 @@ alter table t1 max_rows=100000000000; show create table t1; drop table t1; +# +# Bug#17530: Incorrect key truncation on table creation caused server crash. +# +create table t1(f1 varchar(800) binary not null, key(f1)) engine = innodb + character set utf8 collate utf8_general_ci; +insert into t1 values('aaa'); +drop table t1; + # End of 5.0 tests diff --git a/sql/sql_table.cc b/sql/sql_table.cc index de350b83985..a84d70f7835 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1299,7 +1299,9 @@ static int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, } if (length > file->max_key_part_length() && key->type != Key::FULLTEXT) { - length=file->max_key_part_length(); + length= file->max_key_part_length(); + /* Align key length to multibyte char boundary */ + length-= length % sql_field->charset->mbmaxlen; if (key->type == Key::MULTIPLE) { /* not a critical problem */