MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string)

Item_func_substr::fix_length_and_dec() incorrecltly calculated its max_length
to 0 when a huge number was passed as the third argument:
  substring('hello', 1, 4294967295)
Fixing this.
This commit is contained in:
Alexander Barkov 2024-11-11 10:00:26 +04:00
parent 09fe74c7fd
commit 74184074a0
3 changed files with 19 additions and 4 deletions

View file

@ -5330,5 +5330,13 @@ BIN(c)
DROP TABLE t1;
DO OCT(-9223372036854775808);
#
# MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string)
#
create view v1 as select substring('hello', 1, 4294967295);
select * from v1;
substring('hello', 1, 4294967295)
hello
drop view v1;
#
# End of 10.5 tests
#

View file

@ -2370,6 +2370,13 @@ DROP TABLE t1;
DO OCT(-9223372036854775808);
--echo #
--echo # MDEV-28652 SUBSTRING(str,pos,len) returns incorrect result in view (returns an empty string)
--echo #
create view v1 as select substring('hello', 1, 4294967295);
select * from v1;
drop view v1;
--echo #
--echo # End of 10.5 tests

View file

@ -1773,11 +1773,11 @@ bool Item_func_substr::fix_length_and_dec()
}
if (arg_count == 3 && args[2]->const_item())
{
int32 length= (int32) args[2]->val_int();
if (args[2]->null_value || length <= 0)
longlong length= args[2]->val_int();
if (args[2]->null_value || (length <= 0 && !args[2]->unsigned_flag))
max_length=0; /* purecov: inspected */
else
set_if_smaller(max_length,(uint) length);
else if (length < UINT32_MAX)
set_if_smaller(max_length, (uint32) length);
}
max_length*= collation.collation->mbmaxlen;
return FALSE;