| 1 |
--source include/have_file_key_management.inc |
| 2 |
--source include/innodb_page_size.inc |
| 3 |
|
| 4 |
call mtr.add_suppression("\\[ERROR\\] InnoDB: The page \\[page id: space=[1-9][0-9]*, page number=3\\] in file '.*test.t1\\.ibd' cannot be decrypted."); |
| 5 |
call mtr.add_suppression("\\[ERROR\\] InnoDB: Failed to read page 3 from file '.*test/t1\\.ibd'"); |
| 6 |
call mtr.add_suppression("\\[ERROR\\] InnoDB: File '.*test/t1\\.ibd' is corrupted"); |
| 7 |
call mtr.add_suppression("\\[ERROR\\] InnoDB: Table `test`\\.`t1` has an unreadable root page"); |
| 8 |
CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes; |
| 9 |
insert into t1 select repeat('a',100); |
| 10 |
|
| 11 |
let MYSQLD_DATADIR=`select @@datadir`; |
| 12 |
let INNODB_PAGE_SIZE=`select @@innodb_page_size`; |
| 13 |
|
| 14 |
--source include/shutdown_mysqld.inc |
| 15 |
|
| 16 |
--echo # Corrupt the table |
| 17 |
|
| 18 |
perl; |
| 19 |
use strict; |
| 20 |
use warnings; |
| 21 |
use Fcntl qw(:DEFAULT :seek); |
| 22 |
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl"; |
| 23 |
|
| 24 |
my $ps = $ENV{INNODB_PAGE_SIZE}; |
| 25 |
|
| 26 |
sysopen IBD_FILE, "$ENV{MYSQLD_DATADIR}/test/t1.ibd", O_RDWR |
| 27 |
|| die "Cannot open t1.ibd\n"; |
| 28 |
sysread(IBD_FILE, $_, 58) || die "Cannot read t1.ibd\n"; |
| 29 |
my $space = unpack("x[34]N", $_); |
| 30 |
my $full_crc32 = unpack("N",substr($_,54,4)) & 0x10; # FIL_SPACE_FLAGS |
| 31 |
sysseek(IBD_FILE, $ps * 3, SEEK_SET) || die "Cannot seek t1.ibd\n"; |
| 32 |
|
| 33 |
# better to have a valid page number (3) |
| 34 |
my $page = pack("x[4]Nx[18]Nx[4]N", 3, 1, $space) . chr(0) x ($ps - 38); |
| 35 |
|
| 36 |
my $polynomial = 0x82f63b78; # CRC-32C |
| 37 |
if ($full_crc32) |
| 38 |
{ |
| 39 |
# no possibility of bug here |
| 40 |
my $ck = mycrc32(substr($page, 0, $ps - 4), 0, $polynomial); |
| 41 |
substr($page, $ps - 4, 4) = pack("N", $ck); |
| 42 |
} |
| 43 |
else |
| 44 |
{ |
| 45 |
my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^ |
| 46 |
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial)); |
| 47 |
substr($page,0,4)=$ck; |
| 48 |
substr($page,$ps-8,4)=$ck; |
| 49 |
# trigger the bug by having the same "post-encryption" checksum! |
| 50 |
substr($page,30,4)=$ck; |
| 51 |
} |
| 52 |
|
| 53 |
die unless syswrite(IBD_FILE, $page, $ps) == $ps; |
| 54 |
close IBD_FILE; |
| 55 |
EOF |
| 56 |
|
| 57 |
--source include/start_mysqld.inc |
| 58 |
|
| 59 |
echo # xtrabackup backup; |
| 60 |
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; |
| 61 |
let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log; |
| 62 |
|
| 63 |
let $expect_error= 1; |
| 64 |
if (`select @@innodb_checksum_algorithm LIKE '%full_crc32'`) |
| 65 |
{ |
| 66 |
let $expect_error= 0; |
| 67 |
} |
| 68 |
--disable_result_log |
| 69 |
--error $expect_error |
| 70 |
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --parallel=10 --extended-validation --target-dir=$targetdir --core-file > $backuplog; |
| 71 |
--enable_result_log |
| 72 |
|
| 73 |
|
| 74 |
--let SEARCH_PATTERN=Database page corruption detected.* |
| 75 |
--let SEARCH_FILE=$backuplog |
| 76 |
--source include/search_pattern_in_file.inc |
| 77 |
remove_file $backuplog; |
| 78 |
rmdir $targetdir; |
| 79 |
|
| 80 |
# Due to very constructed nature of the "corruption" (faking checksums), the "corruption" won't be found without --extended-validation |
| 81 |
--disable_result_log |
| 82 |
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --parallel=10 --target-dir=$targetdir; |
| 83 |
--enable_result_log |
| 84 |
|
| 85 |
drop table t1; |
| 86 |
rmdir $targetdir; |