Bug #120391 CONVERT(... USING utf8mb4) silently replaces unconvertible CJK bytes without warning
Submitted: 2 May 3:57 Modified: 4 May 6:54
Reporter: chen zhongpu Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version: OS:Any
Assigned to: CPU Architecture:Any

[2 May 3:57] chen zhongpu
Description:
This bug is related to https://bugs.mysql.com/bug.php?id=120384.

`CONVERT(... USING utf8mb4)` along will generate a warning when the bytes are invalid, however when it used in a table, it silently replaces unconvertible CJK bytes without warning.

How to repeat:
```
CREATE TABLE g (
   id int primary key,
   s varchar(10) character set gbk
);

INSERT INTO g VALUES(1, 0xA140);
```

```
MySQL [myedb]> SELECT id, s, hex(s), CONVERT(s USING utf8mb4) FROM g;
+----+------+--------+--------------------------+
| id | s    | hex(s) | CONVERT(s USING utf8mb4) |
+----+------+--------+--------------------------+
|  1 | ?    | A140   | ?                        |
+----+------+--------+--------------------------+
1 row in set (0.000 sec)

MySQL [myedb]> SELECT CONVERT(0xA140 USING utf8mb4);
+-------------------------------+
| CONVERT(0xA140 USING utf8mb4) |
+-------------------------------+
| NULL                          |
+-------------------------------+
1 row in set, 1 warning (0.001 sec)
```
[4 May 6:54] Roy Lyseng
Thank you for the bug report.

However, I don't think this is actually a bug.
The string that converts successfully is a GBK string, whereas the string that causes a warning is a binary string. To prove this, execute:

  SELECT CONVERT(_gbk x'A140' USING utf8mb4);

which will also execute successfully.