diff --git a/mysql-test/r/ctype_utf8mb4.result b/mysql-test/r/ctype_utf8mb4.result index d43f3b0e0bd..4de7a192546 100644 --- a/mysql-test/r/ctype_utf8mb4.result +++ b/mysql-test/r/ctype_utf8mb4.result @@ -2438,6 +2438,9 @@ t1 CREATE TABLE `t1` ( INSERT INTO t1(subject) VALUES ('abcd'); INSERT INTO t1(subject) VALUES(x'f0909080'); DROP TABLE t1; +CREATE TABLE t1 (a TEXT CHARACTER SET utf8mb4, FULLTEXT INDEX(a)); +INSERT INTO t1 VALUES (0xF0A08080 /* U+20000 */ ); +DROP TABLE t1; # # Bug #51676 Server crashes on SELECT, ORDER BY on 'utf8mb4' column # diff --git a/mysql-test/t/ctype_utf8mb4.test b/mysql-test/t/ctype_utf8mb4.test index 8916de670c1..f396d36e5b0 100644 --- a/mysql-test/t/ctype_utf8mb4.test +++ b/mysql-test/t/ctype_utf8mb4.test @@ -1763,6 +1763,13 @@ INSERT INTO t1(subject) VALUES ('abcd'); INSERT INTO t1(subject) VALUES(x'f0909080'); DROP TABLE t1; +# +# Make sure fulltext does not crash on supplementary characters +# +CREATE TABLE t1 (a TEXT CHARACTER SET utf8mb4, FULLTEXT INDEX(a)); +INSERT INTO t1 VALUES (0xF0A08080 /* U+20000 */ ); +DROP TABLE t1; + --echo # --echo # Bug #51676 Server crashes on SELECT, ORDER BY on 'utf8mb4' column --echo # diff --git a/strings/ctype-mb.c b/strings/ctype-mb.c index 98b598c3c2c..b1b381da59e 100644 --- a/strings/ctype-mb.c +++ b/strings/ctype-mb.c @@ -1123,8 +1123,16 @@ size_t my_numcells_mb(CHARSET_INFO *cs, const char *b, const char *e) continue; } b+= mb_len; - pg= (wc >> 8) & 0xFF; - clen+= utr11_data[pg].p ? utr11_data[pg].p[wc & 0xFF] : utr11_data[pg].page; + if (wc > 0xFFFF) + { + if (wc >= 0x20000 && wc <= 0x3FFFD) /* CJK Ideograph Extension B, C */ + clen+= 1; + } + else + { + pg= (wc >> 8) & 0xFF; + clen+= utr11_data[pg].p ? utr11_data[pg].p[wc & 0xFF] : utr11_data[pg].page; + } clen++; } return clen; @@ -1136,7 +1144,7 @@ int my_mb_ctype_mb(CHARSET_INFO *cs, int *ctype, { my_wc_t wc; int res= cs->cset->mb_wc(cs, &wc, s, e); - if (res <= 0) + if (res <= 0 || wc > 0xFFFF) *ctype= 0; else *ctype= my_uni_ctype[wc>>8].ctype ?