Commit 30f3db3c authored by Alexander Barkov's avatar Alexander Barkov

MDEV-29019 Assertion `(length % 4) == 0' failed in my_lengthsp_utf32 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.
parent 9e5c1fb5
...@@ -2940,3 +2940,23 @@ DROP TABLE t1; ...@@ -2940,3 +2940,23 @@ DROP TABLE t1;
# #
# End of 10.2 tests # 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
#
...@@ -1099,7 +1099,30 @@ CREATE TABLE t1 ( ...@@ -1099,7 +1099,30 @@ CREATE TABLE t1 (
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
DROP TABLE t1; DROP TABLE t1;
--enable_service_connection
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --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
...@@ -3533,8 +3533,12 @@ String *Item_func_conv::val_str(String *str) ...@@ -3533,8 +3533,12 @@ String *Item_func_conv::val_str(String *str)
from_base, &endptr, &err); from_base, &endptr, &err);
} }
uint dummy_errors;
if (!(ptr= longlong2str(dec, ans, to_base)) || 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; null_value= 1;
return NULL; return NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment