Skip to content

Commit f9b50c0

Browse files
committed
MDEV-13512 buf_flush_update_zip_checksum() corrupts SPATIAL INDEX in ROW_FORMAT=COMPRESSED tables
In MariaDB Server 10.1, this problem manifests itself only as a debug assertion failure in page_zip_decompress() when an insert requires a page to be decompressed. In MariaDB 10.1, the encryption of InnoDB data files repurposes the previously unused field FILE_FLUSH_LSN for an encryption key version. This field was only used in the first page of each file of the system tablespace. For ROW_FORMAT=COMPRESSED tables, the field was always written as 0 until encryption was implemented. There is no bug in the encryption, because the buffer pool blocks will not be written to files. Instead, copies of the blocks will be encrypted. In these encrypted copies, the key version field will be updated before the buffer is written to the file. The field in the buffer pool is basically garbage that does not really matter. Already in MariaDB 10.0, the memset() calls to reset this unused field in buf_flush_update_zip_checksum() and buf_flush_write_block_low() are unnecessary, because fsp_init_file_page_low() would guarantee that the field is always 0 in the buffer pool (unless 10.1 encryption is used). Removing the unnecessary memset() calls makes page_zip_decompress() happy and will prevent a SPATIAL INDEX corruption bug in MariaDB Server 10.2. In MySQL 5.7.5, as part of WL#6968, the same field was repurposed for an R-tree split sequence number (SSN) and these memset() were removed. (Because of the repurposing, MariaDB encryption is not available for tables that contain SPATIAL INDEX.)
1 parent 1cfaafa commit f9b50c0

File tree

2 files changed

+0
-6
lines changed

2 files changed

+0
-6
lines changed

storage/innobase/buf/buf0flu.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ buf_flush_update_zip_checksum(
715715
srv_checksum_algorithm)));
716716

717717
mach_write_to_8(page + FIL_PAGE_LSN, lsn);
718-
memset(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION, 0, 8);
719718
mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, checksum);
720719
}
721720

@@ -894,8 +893,6 @@ buf_flush_write_block_low(
894893
bpage->newest_modification);
895894

896895
ut_a(page_zip_verify_checksum(frame, zip_size));
897-
898-
memset(frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION, 0, 8);
899896
break;
900897
case BUF_BLOCK_FILE_PAGE:
901898
frame = bpage->zip.data;

storage/xtradb/buf/buf0flu.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ buf_flush_update_zip_checksum(
757757
srv_checksum_algorithm)));
758758

759759
mach_write_to_8(page + FIL_PAGE_LSN, lsn);
760-
memset(page + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION, 0, 8);
761760
mach_write_to_4(page + FIL_PAGE_SPACE_OR_CHKSUM, checksum);
762761
}
763762

@@ -935,8 +934,6 @@ buf_flush_write_block_low(
935934
bpage->newest_modification);
936935

937936
ut_a(page_zip_verify_checksum(frame, zip_size));
938-
939-
memset(frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION, 0, 8);
940937
break;
941938
case BUF_BLOCK_FILE_PAGE:
942939
frame = bpage->zip.data;

0 commit comments

Comments
 (0)