dolthub / dolthub/dolt

JSON column accepts binary-charset strings that MySQL rejects, silently corrupting non-ASCII bytes

Open
#11,216 0 comments 0 reactions 0 assignees View on GitHub
bug correctness json
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 5h
Merged PRs (30d)
108

Description

Dolt accepts creating a JSON value from a binary character set string. MySQL rejects this with ERROR 3144 (22032): "Cannot create a JSON value from a string with CHARACTER SET 'binary'." For non-ASCII bytes, Dolt's silent acceptance also corrupts the data.

Functions like CHAR(...) return a binary string, and CONCAT of a binary string is binary, so building a JSON literal that way yields a binary-charset value.
```mysql
CREATE TABLE t (j JSON);
INSERT INTO t VALUES (CONCAT('"', CHAR(65), '"'));
SELECT j, JSON_TYPE(j) FROM t;

-- dolt
+-----+--------------+
| j | json_type(j) |
+-----+--------------+
| "A" | STRING |
+-----+--------------+

CREATE TABLE t (j JSON);
INSERT INTO t VALUES (CONCAT('"', CHAR(233), '"')); -- 0xE9
SELECT JSON_VALID(j), HEX(CAST(j AS CHAR)) FROM t;

+-------------+------------+
| json_valid | hex_bytes |
+-------------+------------+
| true | 22EFBFBD22 |
+-------------+------------+

-- mysql
ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
```

`22 EF BF BD 22` = '"' + `U+FFFD` + '"'. The original byte `0xE9` was silently replaced with the Unicode replacement character. For pure ASCII (`CHAR(65)`) the coerced value happens to be correct. The data loss appears once a non-ASCII or invalid-UTF-8 byte is involved.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.