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

Malformed result for CONCAT(utf8_column, binary_string)

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 5.3.12, 5.5.38, 10.0.13
    • 10.0.14
    • None
    • None

    Description

      This script:

      drop table if exists t1;
      create table t1 (a varchar(10) character set utf8);
      insert into t1 values ('aaa');
      select concat(a, 0xFF), charset(concat(a, 0xFF)) from t1;

      returns a badly formed result:

      +-----------------+--------------------------+
      | concat(a, 0xFF) | charset(concat(a, 0xFF)) |
      +-----------------+--------------------------+
      | aaa�             | utf8                     |
      +-----------------+--------------------------+

      Notice, character set of the result is utf8, but the returned string
      is not a valid utf8 string.

      The correct behaviour would be to return an error, as 0xFF is a bad utf8 string.

      A similar problem happens with UNION:

      drop table if exists t1;
      create table t1 (a varchar(10) character set utf8);
      insert into t1 values ('aaa');
      select a from t1 union select 0xFF;
      show warnings;

      returns:

      +------+
      | a    |
      +------+
      | aaa  |
      |      |
      +------+
      2 rows in set, 1 warning (0.00 sec)
       
      +---------+------+--------------------------------------------------------+
      | Level   | Code | Message                                                |
      +---------+------+--------------------------------------------------------+
      | Warning | 1366 | Incorrect string value: '\xFF' for column 'a' at row 2 |
      +---------+------+--------------------------------------------------------+
      1 row in set (0.00 sec)

      The correct behaviour would be to return an error.

      Attachments

        Activity

          bar Alexander Barkov created issue -
          bar Alexander Barkov made changes -
          Field Original Value New Value
          Description This script:
          {code:sql}
          drop table if exists t1;
          create table t1 (a varchar(10) character set utf8);
          insert into t1 values ('aaa');
          select concat(a, 0xFF), charset(concat(a, 0xFF)) from t1;
          {code}
          returns a badly formed result:
          {noformat}
          +-----------------+--------------------------+
          | concat(a, 0xFF) | charset(concat(a, 0xFF)) |
          +-----------------+--------------------------+
          | aaa� | utf8 |
          +-----------------+--------------------------+
          {noformat}

          Notice, character set of the result is utf8, but the returned string
          is not a valid utf8 string.

          The correct behaviour would be to return an error, as 0xFF is a bad utf8 string.
          This script:
          {code:sql}
          drop table if exists t1;
          create table t1 (a varchar(10) character set utf8);
          insert into t1 values ('aaa');
          select concat(a, 0xFF), charset(concat(a, 0xFF)) from t1;
          {code}
          returns a badly formed result:
          {noformat}
          +-----------------+--------------------------+
          | concat(a, 0xFF) | charset(concat(a, 0xFF)) |
          +-----------------+--------------------------+
          | aaa� | utf8 |
          +-----------------+--------------------------+
          {noformat}

          Notice, character set of the result is utf8, but the returned string
          is not a valid utf8 string.

          The correct behaviour would be to return an error, as 0xFF is a bad utf8 string.

          A similar problem happens with UNION:
          {code:sql}
          drop table if exists t1;
          create table t1 (a varchar(10) character set utf8);
          insert into t1 values ('aaa');
          select a from t1 union select 0xFF;
          show warnings;
          {code}
          returns:
          {noformat}
          +------+
          | a |
          +------+
          | aaa |
          | |
          +------+
          2 rows in set, 1 warning (0.00 sec)

          +---------+------+--------------------------------------------------------+
          | Level | Code | Message |
          +---------+------+--------------------------------------------------------+
          | Warning | 1366 | Incorrect string value: '\xFF' for column 'a' at row 2 |
          +---------+------+--------------------------------------------------------+
          1 row in set (0.00 sec)
          {noformat}

          The correct behaviour would be to return an error.
          bar Alexander Barkov made changes -
          Fix Version/s 10.0.14 [ 17101 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Workflow MariaDB v2 [ 53317 ] MariaDB v3 [ 64566 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 64566 ] MariaDB v4 [ 148176 ]

          People

            bar Alexander Barkov
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

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