Bug #21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
Submitted: 3 Aug 2006 16:31 Modified: 18 Jun 2010 1:02
Reporter: Andrey Hristov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1, 5.0, 5.1 OS:Any (All)
Assigned to: Sergey Glukhov CPU Architecture:Any
Tags: Q1

[3 Aug 2006 16:31] Andrey Hristov
Description:
The server code uses define NAME_LEN which is 64. All around the server code NAME_LEN is used for stack allocated buffers as well as in 
bool check_table_name(const char *name, uint length)
{
  const char *end= name+length;
  if (!length || length > NAME_LEN)
    return 1;
...
}
Because the server internally uses UTF-8 as encoding, this means that characters from cyrillic, greek and others which are represented with two bytes effectively lower the upper limit of a characters that can constitute a table name, database name too (see check_db_name()).

How to repeat:
-- table name which is 26 chars -> 52 bytes
mysql> create table много_дълго_име_на_таблица(a int);
Query OK, 0 rows affected (1.13 sec)

-- table name which is 44 chars -> 88 bytes

mysql> create table много_дълго_име_на_таблица_още_няколко_букви(a int);
ERROR 1103 (42000): Incorrect table name 'много_дълго_име_на_таблица_още_няколко_букви'

mysql> create database много_дълго_име_на_база_данни;
Query OK, 1 row affected (4.25 sec)

mysql> create database много_дълго_име_на_база_данни_още_малко;
ERROR 1102 (42000): Incorrect database name 'много_дълго_име_на_база_данни_още_малко'

Suggested fix:
Change usage of NAME_LEN. Maybe introduce NAME_LEN_BYTES and separate usage of both macroses.
[3 Aug 2006 19:16] Sveta Smirnova
Verified as described using 4.1, 5.0 and 5.1 BK sources.
[15 Aug 2006 10:18] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10446

ChangeSet@1.2226, 2006-08-15 15:34:41+05:00, gluh@mysql.com +7 -0
  Bug#20393 User name truncation in mysql client
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
[23 Aug 2006 10:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10752

ChangeSet@1.2544, 2006-08-23 15:54:40+05:00, gluh@mysql.com +7 -0
  Bug#20393 User name truncation in mysql client
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
[25 Aug 2006 18:54] Andrey Hristov
Gluh will have some problems while merging 4.1 into 5.0 because of Alik's patch for #16899 Possible buffer overflow in handling of DEFINER-clause.
Gluh, Alik's patch is again not multibyte safe so you have to rework the things for 5.0 and up.
[30 Aug 2006 10:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/11066

ChangeSet@1.2548, 2006-08-30 15:56:17+05:00, gluh@mysql.com +7 -0
  Bug#20393 User name truncation in mysql client
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
[30 Aug 2006 11:06] Sergey Glukhov
Fixed in 4.1.22
[12 Sep 2006 1:17] Paul Dubois
Noted in 4.1.22 changelog.

Database and table names have a maximum length of 64 characters (even
if they contain multi-byte characters), but were being truncated to64 bytes.
[18 Sep 2006 21:59] Timothy Smith
Pushed to 5.0.25 and 5.1.12
[19 Sep 2006 16:46] Paul Dubois
Noted in 5.0.25, 5.1.12 changelogs.
[26 Sep 2006 18:29] Michael Widenius
This patch needs to be removed from 4.1 and 5.0 becasue this may crash clients that is using NAME_LEN for static buffers.

Jani has sent a suggestion to gluh for how to fix this bug in 5.1 in a manner that will have cause less problems for old and new clients
[27 Sep 2006 12:36] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12605

ChangeSet@1.2551, 2006-09-27 17:49:16+05:00, gluh@mysql.com +7 -0
  Patch for bug#21432 is reverted
[26 Dec 2006 9:56] Sveta Smirnova
Bug #25165 has been marked as duplicate of this one
[26 Jan 2007 12:02] Sveta Smirnova
Bug #25832 was marked as duplicate of this one
[19 Mar 2007 12:41] Sergey Glukhov
ChangeSet@1.2477, 2007-03-19
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
[3 Apr 2007 14:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/23684

ChangeSet@1.2553, 2007-04-03 19:40:55+05:00, gluh@mysql.com +1 -0
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
  additional fix
[4 Apr 2007 12:38] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/23780

ChangeSet@1.2554, 2007-04-04 17:36:58+05:00, gluh@mysql.com +2 -0
  Bug#21432 Database/Table name limited to 64 bytes, not chars, problems with multi-byte
  additional fix(to satisfy Win where CreateFile func does not support the path longer than 260)
[9 Apr 2007 10:02] Alexander Nozdrin
Patch for this bug also fixes BUG#21564
(SP: SHOW CREATE PROCEDURE says identifier too long,
but the procedure exists).
[9 Apr 2007 12:41] Bugs System
Pushed into 5.1.18-beta
[12 Apr 2007 16:11] Paul Dubois
Noted in 5.1.18 changelog.

Database and table names have a maximum length of 64 characters (even
if they contain multi-byte characters), but were being truncated to64 bytes.

The patch in 4.1.23 was reverted. I removed the 4.1.23 changelog entry.
The patch in 5.0.25 was reverted in 5.0.26. I added a note about this
to the 5.0.25 changelog entry.
[16 Dec 2009 23:31] Miguel Solorzano
See bug: http://bugs.mysql.com/bug.php?id=49752.
[5 May 2010 15:18] Bugs System
Pushed into 5.1.47 (revid:joro@sun.com-20100505145753-ivlt4hclbrjy8eye) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[6 May 2010 2:22] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug. Re-closing.
[28 May 2010 5:50] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100524190136-egaq7e8zgkwb9aqi) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (pib:16)
[28 May 2010 6:19] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100524190941-nuudpx60if25wsvx) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[28 May 2010 6:47] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100524185725-c8k5q7v60i5nix3t) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[28 May 2010 21:41] Paul Dubois
Push resulted from incorporation of InnoDB tree. No changes pertinent to this bug.
Re-closing.
[17 Jun 2010 11:51] Bugs System
Pushed into 5.1.47-ndb-7.0.16 (revid:martin.skold@mysql.com-20100617114014-bva0dy24yyd67697) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 12:28] Bugs System
Pushed into 5.1.47-ndb-6.2.19 (revid:martin.skold@mysql.com-20100617115448-idrbic6gbki37h1c) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)
[17 Jun 2010 13:16] Bugs System
Pushed into 5.1.47-ndb-6.3.35 (revid:martin.skold@mysql.com-20100617114611-61aqbb52j752y116) (version source revid:vasil.dimov@oracle.com-20100331130613-8ja7n0vh36a80457) (merge vers: 5.1.46) (pib:16)