Skip to content

Fix offset check for insert position overflow #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mysql-test/r/func_str.result
Original file line number Diff line number Diff line change
Expand Up @@ -5822,3 +5822,10 @@ SELECT QUOTE(x'80');
ERROR HY000: Cannot convert string '\x80' from binary to utf8mb4
SELECT QUOTE(_utf8mb4 x'80');
ERROR HY000: Invalid utf8mb4 character string: '80'
#
# Bug: The insert function does handle inserting beyond the string for multibyte characters
#
set names utf8mb4;
select insert('Å', 2, 1, 'a');
insert('Å', 2, 1, 'a')
6 changes: 6 additions & 0 deletions mysql-test/t/func_str.test
Original file line number Diff line number Diff line change
Expand Up @@ -2675,3 +2675,9 @@ SELECT QUOTE(NULL);
SELECT QUOTE(x'80');
--error ER_INVALID_CHARACTER_STRING
SELECT QUOTE(_utf8mb4 x'80');

--echo #
--echo # Bug: The insert function does handle inserting beyond the string for multibyte characters
--echo #
set names utf8mb4;
select insert('Å', 2, 1, 'a');
2 changes: 1 addition & 1 deletion sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ String *Item_func_insert::val_str(String *str) {
res->charpos(static_cast<size_t>(length), static_cast<size_t>(start));

/* Re-testing with corrected params */
if (start > orig_len)
if (start >= orig_len)
return res; /* purecov: inspected */ // Wrong param; skip insert
if (length > orig_len - start) length = orig_len - start;

Expand Down