Bug #18038 MySQL server corrupts binary columns data
Submitted: 7 Mar 2006 16:01 Modified: 18 Mar 2006 7:25
Reporter: Andrey Hristov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:5.1.8-bk OS:Linux (SuSE 9.3)
Assigned to: Jani Tolonen CPU Architecture:Any

[7 Mar 2006 16:01] Andrey Hristov
Description:
mysql> create table corrupt(db char(64) character set utf8 collate utf8_bin default '');
Query OK, 0 rows affected (0.15 sec)

 Shortening and extending a char column with binary collation increases the length and probably corrupts the data of the column.

mysql> insert into corrupt values ('test');
Query OK, 1 row affected (0.07 sec)

mysql> select length(db) from corrupt;
+------------+
| length(db) |
+------------+
|          4 |
+------------+
1 row in set (0.05 sec)

mysql> ALTER TABLE corrupt MODIFY db char(20) character set utf8 collate utf8_bin default '';
Query OK, 1 row affected (0.49 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select length(db) from corrupt;
+------------+
| length(db) |
+------------+
|          4 |
+------------+
1 row in set (0.08 sec)

mysql> ALTER TABLE corrupt MODIFY db char(64) character set utf8 collate utf8_bin default '';
Query OK, 1 row affected (0.24 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select length(db) from corrupt;
+------------+
| length(db) |
+------------+
|        192 |
+------------+
1 row in set (0.09 sec)

How to repeat:
create table corrupt(db char(64) character set utf8 collate utf8_bin default '');
insert into corrupt values ('test');
select length(db) from corrupt;
ALTER TABLE corrupt MODIFY db char(20) character set utf8 collate utf8_bin default '';
select length(db) from corrupt;
ALTER TABLE corrupt MODIFY db char(64) character set utf8 collate utf8_bin default '';
select length(db) from corrupt;
[7 Mar 2006 16:09] MySQL Verification Team
Thank you for the bug report. This bug NOT affects 4.1/5.0.
[7 Mar 2006 16:21] Andrey Hristov
I have 2 clones.
Tree 1 does not show the error behavior and is based on this changeset:

ChangeSet@1.2212, 2006-03-02 22:53:38+01:00, kent@mysql.com
  mysql-test-run.pl:
    Try find in order 'mysqld-nt', 'mysqld', 'mysqld-debug' and 'mysqld-max'
  mysqld_safe.sh:
    Don't try 'mysqld-max' before 'mysqld' if no server given, bug#17861

Tree 2 is pretty fresh, as Miguel's:
ChangeSet@1.2160.1.1, 2006-03-07 12:19:27+01:00, tomas@poseidon.ndb.mysql.com
  Bug #16874    memory leaks in rpl_row_basic_7ndb.test
  - free ndb shares at server shutdown
  - free_table_share at free of ndb_share

So something happened between March 2n and March 7th
[14 Mar 2006 16:06] 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/3830
[15 Mar 2006 7:57] Jim Winstead
Patch seems like it might be okay, but is lacking a test case.
[15 Mar 2006 8: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/3850
[18 Mar 2006 7:25] Jani Tolonen
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html