Bug #28478 Improper key_cache_block_size corrupts MyISAM tables
Submitted: 16 May 2007 17:05 Modified: 20 Jun 2007 0:51
Reporter: Ingo Strüwing Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:5.0.42, * OS:Any
Assigned to: Ingo Strüwing CPU Architecture:Any
Tags: corruption, myisam. key_cache_block_size

[16 May 2007 17:05] Ingo Strüwing
Description:
Setting a key_cache_block_size which is not a power of 2 corrupts MyISAM tables:

DROP TABLE IF EXISTS t1;
SET GLOBAL key_cache_block_size= 1536;
CREATE TABLE t1 (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
c1 CHAR(150),
c2 CHAR(150),
c3 CHAR(150),
KEY(c1, c2, c3)
) ENGINE= MyISAM;
INSERT INTO t1 (c1, c2, c3) VALUES
('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f'),
('e', 'f', 'g'), ('f', 'g', 'h'), ('g', 'h', 'i'), ('h', 'i', 'j'),
('i', 'j', 'k'), ('j', 'k', 'l'), ('k', 'l', 'm'), ('l', 'm', 'n'),
('m', 'n', 'o'), ('n', 'o', 'p'), ('o', 'p', 'q'), ('p', 'q', 'r'),
('q', 'r', 's'), ('r', 's', 't'), ('s', 't', 'u'), ('t', 'u', 'v'),
('u', 'v', 'w'), ('v', 'w', 'x'), ('w', 'x', 'y'), ('x', 'y', 'z');
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
Warnings:
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
Error	126	Incorrect key file for table './test/t1.MYI'; try to repair it
CHECK TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	check	error	Size of indexfile is: 9728        Should be: 11264
test.t1	check	error	Corrupt
SHOW VARIABLES LIKE 'key_cache_block_size';
Variable_name	Value
key_cache_block_size	1536

How to repeat:
See description.
[16 May 2007 20:22] 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/26878

ChangeSet@1.2465, 2007-05-16 22:22:09+02:00, istruewing@chilla.local +3 -0
  Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
  
  Setting a key_cache_block_size which is not a power of 2
  could corrupt MyISAM tables.
  
  A couple of computations in the key cache code use bit
  operations which do only work if key_cache_block_size
  is a power of 2.
  
  Replaced bit operations by arithmetic operations
  to make key cache able to handle block sizes that are
  not a power of 2.
[31 May 2007 18:05] 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/27838

ChangeSet@1.2466, 2007-05-31 20:04:54+02:00, istruewing@chilla.local +4 -0
  Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
  
  Setting a key_cache_block_size which is not a power of 2
  could corrupt MyISAM tables.
  
  A couple of computations in the key cache code use bit
  operations which do only work if key_cache_block_size
  is a power of 2.
  
  Replaced bit operations by arithmetic operations
  to make key cache able to handle block sizes that are
  not a power of 2.
[4 Jun 2007 10:17] Ingo Strüwing
Queued to 5.1-engines and 5.0-engines.
[18 Jun 2007 7:48] Bugs System
Pushed into 5.1.20-beta
[18 Jun 2007 7:50] Bugs System
Pushed into 5.0.44
[18 Jun 2007 19:55] Paul DuBois
Noted in 5.0.44, 5.1.20 changelogs.
[19 Jun 2007 10:27] Daniel Fischer
Didn't make it into 5.0.44, will be in 5.0.46.
[20 Jun 2007 0:51] Paul DuBois
Moved 5.0.44 changelog entry to 5.0.46.
[20 Jun 2007 1:02] Paul DuBois
Revised changelog entry:

The server deducted some bytes from the key_cache_block_size option
value and reduced it to the next lower 512 byte boundary. The
resulting block size was not a power of two. Setting the 
key_cache_block_size system variable to a value that is not a power
of two resulted in MyISAM table corruption.

(This description applies to Bug#23068, Bug#25853, Bug#28478)