diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 09ed83dc216..a15a253df0c 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5332,3 +5332,17 @@ DO OCT(-9223372036854775808); # # End of 10.5 tests # +# +# Start of 10.6 tests +# +# +# MDEV-29552 LEFT and RIGHT with big value for parameter 'len' >0 return empty value in view +# +create view v1 as select left('hello', 4294967295); +select * from v1; +left('hello', 4294967295) +hello +drop view v1; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 8a33b8e8d40..ecbc1157c87 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2380,3 +2380,19 @@ DO OCT(-9223372036854775808); --echo # --echo # End of 10.5 tests --echo # + +--echo # +--echo # Start of 10.6 tests +--echo # + +--echo # +--echo # MDEV-29552 LEFT and RIGHT with big value for parameter 'len' >0 return empty value in view +--echo # + +create view v1 as select left('hello', 4294967295); +select * from v1; +drop view v1; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index efcacd0cba0..b4ccc2611a3 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -64,11 +64,14 @@ size_t username_char_length= USERNAME_CHAR_LENGTH; static uint32 max_length_for_string(Item *item) { ulonglong length= item->val_int(); - /* Note that if value is NULL, val_int() returned 0 */ + if (item->null_value) + return 0; + if (length > (ulonglong) LONGLONG_MAX && !item->unsigned_flag) + return 0; // Negative if (length > (ulonglong) INT_MAX32) { /* Limit string length to maxium string length in MariaDB (2G) */ - length= item->unsigned_flag ? (ulonglong) INT_MAX32 : 0; + length= (ulonglong) INT_MAX32; } return (uint32) length; }