Skip to content

Commit

Permalink
MDEV-29019 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 …
Browse files Browse the repository at this point in the history
…on SELECT

Problem:

Item_func_conv::val_str() copied the ASCII string with the numeric base
conversion result directly to the function result string. In case of a
tricky character set (e.g. utf32) it produced an illformed string.

Fix:

Copy the base conversion result to the function result as is only if
the function character set is ASCII compatible, go through a
character set conversion otherwise.
  • Loading branch information
abarkov committed Jul 19, 2023
1 parent 9e5c1fb commit 30f3db3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions mysql-test/main/ctype_utf32.result
Expand Up @@ -2940,3 +2940,23 @@ DROP TABLE t1;
#
# End of 10.2 tests
#
#
# Start of 10.4 tests
#
#
# MDEV-29019 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 on SELECT
#
CREATE TABLE t (a INT);
SET collation_connection=utf32_unicode_ci;
INSERT INTO t VALUES (0);
SELECT * FROM t ORDER BY (OCT(a));
a
0
SELECT HEX(OCT(a)) FROM t;
HEX(OCT(a))
00000030
DROP TABLE t;
SET NAMES utf8;
#
# End of 10.4 tests
#
25 changes: 24 additions & 1 deletion mysql-test/main/ctype_utf32.test
Expand Up @@ -1099,7 +1099,30 @@ CREATE TABLE t1 (
SHOW CREATE TABLE t1;
DROP TABLE t1;

--enable_service_connection
--echo #
--echo # End of 10.2 tests
--echo #


--echo #
--echo # Start of 10.4 tests
--echo #

--echo #
--echo # MDEV-29019 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 on SELECT
--echo #

CREATE TABLE t (a INT);
SET collation_connection=utf32_unicode_ci;
INSERT INTO t VALUES (0);
SELECT * FROM t ORDER BY (OCT(a));
SELECT HEX(OCT(a)) FROM t;
DROP TABLE t;
SET NAMES utf8;


--echo #
--echo # End of 10.4 tests
--echo #

--enable_service_connection
6 changes: 5 additions & 1 deletion sql/item_strfunc.cc
Expand Up @@ -3533,8 +3533,12 @@ String *Item_func_conv::val_str(String *str)
from_base, &endptr, &err);
}

uint dummy_errors;
if (!(ptr= longlong2str(dec, ans, to_base)) ||
str->copy(ans, (uint32) (ptr - ans), default_charset()))
(collation.collation->state & MY_CS_NONASCII) ?
str->copy(ans, (uint32) (ptr - ans), &my_charset_latin1,
collation.collation, &dummy_errors) :
str->copy(ans, (uint32) (ptr - ans), collation.collation))
{
null_value= 1;
return NULL;
Expand Down

0 comments on commit 30f3db3

Please sign in to comment.