@@ -19,27 +19,36 @@ use warnings;
19
19
use Fcntl qw(:DEFAULT :seek);
20
20
do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
21
21
22
- my $page_size = $ENV{INNODB_PAGE_SIZE};
22
+ my $ps = $ENV{INNODB_PAGE_SIZE};
23
23
24
24
sysopen IBD_FILE, "$ENV{MYSQLD_DATADIR}/test/t1.ibd", O_RDWR
25
25
|| die "Cannot open t1.ibd\n";
26
- sysread(IBD_FILE, $_, 38 ) || die "Cannot read t1.ibd\n";
26
+ sysread(IBD_FILE, $_, 58 ) || die "Cannot read t1.ibd\n";
27
27
my $space = unpack("x[34]N", $_);
28
- sysseek(IBD_FILE, $page_size * 3, SEEK_SET) || die "Cannot seek t1.ibd\n";
28
+ my $full_crc32 = unpack("N",substr($_,54,4)) & 0x10; # FIL_SPACE_FLAGS
29
+ sysseek(IBD_FILE, $ps * 3, SEEK_SET) || die "Cannot seek t1.ibd\n";
29
30
30
- my $head = pack("Nx[18]", 3); # better to have a valid page number
31
- my $body = chr(0) x ($page_size - 38 - 8 );
31
+ # better to have a valid page number (3)
32
+ my $page = pack("x[4]Nx[18]Nx[4]N", 3, 1, $space) . chr(0) x ($ps - 38);
32
33
33
- # Calculate innodb_checksum_algorithm=crc32 for the unencrypted page.
34
- # The following bytes are excluded:
35
- # bytes 0..3 (the checksum is stored there)
36
- # bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
37
- # bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
38
34
my $polynomial = 0x82f63b78; # CRC-32C
39
- my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
40
-
41
- my $page= pack("N",$ck).$head.pack("NNN",1,$ck,$space).$body.pack("Nx[4]",$ck);
42
- die unless syswrite(IBD_FILE, $page, $page_size) == $page_size;
35
+ if ($full_crc32)
36
+ {
37
+ # no possibility of bug here
38
+ my $ck = mycrc32(substr($page, 0, $ps - 4), 0, $polynomial);
39
+ substr($page, $ps - 4, 4) = pack("N", $ck);
40
+ }
41
+ else
42
+ {
43
+ my $ck= pack("N",mycrc32(substr($page, 4, 22), 0, $polynomial) ^
44
+ mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial));
45
+ substr($page,0,4)=$ck;
46
+ substr($page,$ps-8,4)=$ck;
47
+ # trigger the bug by having the same "post-encryption" checksum!
48
+ substr($page,30,4)=$ck;
49
+ }
50
+
51
+ die unless syswrite(IBD_FILE, $page, $ps) == $ps;
43
52
close IBD_FILE;
44
53
EOF
45
54
@@ -49,8 +58,13 @@ echo # xtrabackup backup;
49
58
let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
50
59
let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log;
51
60
61
+ let $expect_error= 1;
62
+ if (`select @@innodb_checksum_algorithm LIKE '%full_crc32'`)
63
+ {
64
+ let $expect_error= 0;
65
+ }
52
66
--disable_result_log
53
- --error 1
67
+ --error $expect_error
54
68
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --extended-validation --target-dir=$targetdir --core-file > $backuplog;
55
69
--enable_result_log
56
70
0 commit comments