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

"USE dbname" with a bad sequence erroneously connects to a wrong database

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.3.12, 5.5.39, 10.0.14
    • Fix Version/s: 10.1.4
    • Component/s: Character Sets
    • Labels:
      None

      Description

      I create a database with some question marks in the name:

      DROP DATABASE IF EXISTS `test????`;
      CREATE DATABASE `test????`;
      

      Now I run a "USE" query with a bad byte sequence:

      SET NAMES utf8;
      USE `test๐Ÿ˜`;
      SELECT DATABASE(), HEX(DATABASE());
      

      (notice. '๐Ÿ˜' is a four-byte UTF-8 character, which is considered as a wrong
      byte sequence by MariaDB's 3-byte "utf8").

      It erroneously connects to the database 'test????':

      ariaDB [(none)]> SET NAMES utf8;
      Query OK, 0 rows affected (0.00 sec)
      
      MariaDB [(none)]> USE `test๐Ÿ˜`;
      Database changed
      MariaDB [test๐Ÿ˜]> SELECT DATABASE(), HEX(DATABASE());
      +------------+------------------+
      | DATABASE() | HEX(DATABASE())  |
      +------------+------------------+
      | test????   | 746573743F3F3F3F |
      +------------+------------------+
      1 row in set (0.00 sec)
      

      The correct behaviour would be report either "unknown database",
      or "bad database name" or "Invalid utf8 character string: 'test\xF0\x9F\x98\x81'".

      The latter would be consistent with what's reported on attempt to
      create a database with such a broken name:

      MariaDB [test]> CREATE DATABASE `test๐Ÿ˜`;
      ERROR 1300 (HY000): Invalid utf8 character string: 'test\xF0\x9F\x98\x81'
      

      A similar problem also happens with table names.
      I create a table with question marks in its name:

      SET NAMES utf8;
      DROP TABLE IF EXISTS `test????`;
      CREATE TABLE `test????` (a INT);
      INSERT INTO `test????` values (10);
      

      Now I change the connection character set to utf8mb4 and run a SELECT query:

      SET NAMES utf8mb4;
      SELECT * FROM `test๐Ÿ˜๐Ÿ˜๐Ÿ˜๐Ÿ˜`;
      

      It returns rows from the table `test????`:

      +------+
      | a    |
      +------+
      |   10 |
      +------+
      1 row in set (0.01 sec)
      

      The expected behaviour would be to return some error.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              There are no comments yet on this issue.

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: