Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-39038

TINYTEXT overflow may return 1366 Incorrect string value instead of 1406 Data too long when truncation splits a UTF-8 character

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 12.2.2
    • 10.11, 11.4, 11.8, 12.3
    • None
    • None

    Description

      Behavior

      Consider the following table:

      CREATE TABLE t (body TINYTEXT) CHARACTER SET utf8mb4;
      

      If the inserted string overflows and the truncation point crosses a multibyte character boundary, MariaDB returns 1366 Incorrect string value:

      INSERT INTO t VALUES ('aあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1366 (22007): Incorrect string value: '\xE3\x81\x82' for column `d`.`t`.`body` at row 1
      

      This error message is misleading because the actual problem is that the value exceeds the column size.

      If the overflow does not cross a multibyte boundary, MariaDB correctly returns 1406 Data too long:

      INSERT INTO t VALUES ('ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1406 (22001): Data too long for column 'body' at row 1
      

      Expected behavior

      Both cases should return 1406 Data too long.

      Logs

      MariaDB 12.2:

      taro@ttg015:~$ docker run -d --name test -e MARIADB_ROOT_PASSWORD=p -e LANG=C.UTF-8 mariadb:12.2 && sleep 20 && docker exec -it test mariadb --default-character-set=utf8mb4 -uroot -pp && docker rm -f test
      0bddc7ee977cd5ecc47c569768f2c149cc0c09d7a78285d76d1605fae19bc856
      Welcome to the MariaDB monitor. Commands end with ; or \g.
      Your MariaDB connection id is 3
      Server version: 12.2.2-MariaDB-ubu2404 mariadb.org binary distribution
       
      Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
       
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       
      MariaDB [(none)]> CREATE DATABASE d;
      Query OK, 1 row affected (0.001 sec)
       
      MariaDB [(none)]> USE d;
      Database changed
      MariaDB [d]> CREATE TABLE t (body TINYTEXT) CHARACTER SET utf8mb4;
      Query OK, 0 rows affected (0.024 sec)
       
      MariaDB [d]> INSERT INTO t VALUES ('aあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1366 (22007): Incorrect string value: '\xE3\x81\x82' for column `d`.`t`.`body` at row 1
      MariaDB [d]> INSERT INTO t VALUES ('ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1406 (22001): Data too long for column 'body' at row 1
      

      For reference, MySQL 9.6 returns 1406 Data too long in both cases:

      taro@ttg015:~$ docker run -d --name test -e MYSQL_ROOT_PASSWORD=p -e LANG=C.UTF-8 mysql:9.6 && sleep 20 && docker exec -it test mysql --default-character-set=utf8mb4 -uroot -pp && docker rm -f test
      b5196fea1727b4300a3ebfed4ae57b2032ffa89df40e7a5216374dd56f12640b
      mysql: [Warning] Using a password on the command line interface can be insecure.
      Welcome to the MySQL monitor. Commands end with ; or \g.
      Your MySQL connection id is 9
      Server version: 9.6.0 MySQL Community Server - GPL
       
      Copyright (c) 2000, 2026, Oracle and/or its affiliates.
       
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
       
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       
      mysql> CREATE DATABASE d;
      Query OK, 1 row affected (0.017 sec)
       
      mysql> USE d;
      Database changed
      mysql> CREATE TABLE t (body TINYTEXT) CHARACTER SET utf8mb4;
      Query OK, 0 rows affected (0.037 sec)
       
      mysql> INSERT INTO t VALUES ('aあああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1406 (22001): Data too long for column 'body' at row 1
      mysql> INSERT INTO t VALUES ('ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ');
      ERROR 1406 (22001): Data too long for column 'body' at row 1
      

      Attachments

        Activity

          People

            rucha174 Rucha Deodhar
            hikaen2 Suzuki Taro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.