Bug #107645 the cast function gets an incorrect result if with wrong encoding
Submitted: 24 Jun 2022 3:00 Modified: 24 Jun 2022 4:51
Reporter: x j Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.7.38, 8.0.29 OS:Any
Assigned to: CPU Architecture:Any

[24 Jun 2022 3:00] x j
Description:
the cast function gets an incorrect result if wrong binary literal to char

How to repeat:
mysql> select cast(0x80 as char);
+--------------------+
| cast(0x80 as char) |
+--------------------+
| �                   |
+--------------------+
1 row in set (0.00 sec)

I think it should report an error like `cannot convert xxx from binary to utf8mb4`
or just return NULL, but not an unknowing character
[24 Jun 2022 4:51] MySQL Verification Team
Hello x j,

Thank you for the report and test case.

regards,
Umesh
[28 Jun 2022 13:48] huahua xu
Hi,

There is not any conversion needed wher the cast function converts xxx from binary to other character set.

mysql>  select convert(0x80 USING utf8mb4);
+-----------------------------+
| convert(0x80 USING utf8mb4) |
+-----------------------------+
| NULL                        |
+-----------------------------+

mysql> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1300 | Invalid utf8mb4 character string: '80' |
+---------+------+----------------------------------------+

the convert function is ok for you?