Skip to content

Commit eb41c11

Browse files
committed
MDEV-33942 View cuts off the end of string with the utf8 character set in INSERT function
Item_func_insert::fix_length_and_dec() incorrectly calculated max_length when its collation.collation evaluated to my_charset_bin. Fixing the code to calculate max_length in terms of octets rather than in terms of characters when collation.collation is my_charset_bin.
1 parent c2bf1d4 commit eb41c11

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

mysql-test/main/func_str.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,5 +5344,16 @@ left('hello', 4294967295)
53445344
hello
53455345
drop view v1;
53465346
#
5347+
# MDEV-33942 View cuts off the end of string with the utf8 character set in INSERT function
5348+
#
5349+
SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
5350+
HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20))
5351+
D120D18E
5352+
CREATE VIEW v1 AS SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
5353+
SELECT * FROM v1;
5354+
HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20))
5355+
D120D18E
5356+
DROP VIEW v1;
5357+
#
53475358
# End of 10.6 tests
53485359
#

mysql-test/main/func_str.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,16 @@ create view v1 as select left('hello', 4294967295);
23932393
select * from v1;
23942394
drop view v1;
23952395

2396+
--echo #
2397+
--echo # MDEV-33942 View cuts off the end of string with the utf8 character set in INSERT function
2398+
--echo #
2399+
2400+
SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
2401+
CREATE VIEW v1 AS SELECT HEX(INSERT(_utf8 0xD18FD18E, 2, 1, 0x20));
2402+
SELECT * FROM v1;
2403+
DROP VIEW v1;
2404+
2405+
23962406
--echo #
23972407
--echo # End of 10.6 tests
23982408
--echo #

sql/item_strfunc.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,12 @@ bool Item_func_insert::fix_length_and_dec()
15621562
// Handle character set for args[0] and args[3].
15631563
if (agg_arg_charsets_for_string_result(collation, args, 2, 3))
15641564
return TRUE;
1565-
char_length= ((ulonglong) args[0]->max_char_length() +
1566-
(ulonglong) args[3]->max_char_length());
1565+
if (collation.collation == &my_charset_bin)
1566+
char_length= (ulonglong) args[0]->max_length +
1567+
(ulonglong) args[3]->max_length;
1568+
else
1569+
char_length= ((ulonglong) args[0]->max_char_length() +
1570+
(ulonglong) args[3]->max_char_length());
15671571
fix_char_length_ulonglong(char_length);
15681572
return FALSE;
15691573
}

0 commit comments

Comments
 (0)