Commit 7f36300d authored by Eugene Kosov's avatar Eugene Kosov

MDEV-21918 improve page_zip_verify_checksum()

actually, page_zip_verify_checksum() generally allows all-zeroes
checksums because our CRC32 checksum is something like
crc_1 ^ crc_2 ^ crc_3

Also, all zeroes page is considered correct.

As a side effect fix nasty reinterpret_cast<> UB

Also, since c0f47a4a innodb_checksum_algorithm=full_crc32
exists which computes CRC32 in one go (without bitwise arithmetic)
parent df88e7ce
...@@ -4918,35 +4918,28 @@ page_zip_verify_checksum( ...@@ -4918,35 +4918,28 @@ page_zip_verify_checksum(
ib_uint32_t crc32 = 0 /* silence bogus warning */; ib_uint32_t crc32 = 0 /* silence bogus warning */;
ib_uint32_t innodb = 0 /* silence bogus warning */; ib_uint32_t innodb = 0 /* silence bogus warning */;
stored = static_cast<ib_uint32_t>(mach_read_from_4( const srv_checksum_algorithm_t curr_algo =
static_cast<const unsigned char*>(data) + FIL_PAGE_SPACE_OR_CHKSUM)); static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm);
#if FIL_PAGE_LSN % 8 if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) {
#error "FIL_PAGE_LSN must be 64 bit aligned" return true;
#endif }
/* Check if page is empty */ bool all_zeroes = true;
if (stored == 0 for (size_t i = 0; i < size; i++) {
&& *reinterpret_cast<const ib_uint64_t*>(static_cast<const char*>( if (static_cast<const byte*>(data)[i] != 0) {
data) all_zeroes = false;
+ FIL_PAGE_LSN) == 0) { break;
/* make sure that the page is really empty */
for (ulint i = 0; i < size; i++) {
if (*((const char*) data + i) != 0) {
return(FALSE);
}
} }
/* Empty page */
return(TRUE);
} }
const srv_checksum_algorithm_t curr_algo = if (all_zeroes) {
static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm); return true;
if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) {
return(TRUE);
} }
stored = static_cast<ib_uint32_t>(mach_read_from_4(
static_cast<const unsigned char*>(data) + FIL_PAGE_SPACE_OR_CHKSUM));
calc = static_cast<ib_uint32_t>(page_zip_calc_checksum( calc = static_cast<ib_uint32_t>(page_zip_calc_checksum(
data, size, curr_algo)); data, size, curr_algo));
......
...@@ -4927,35 +4927,28 @@ page_zip_verify_checksum( ...@@ -4927,35 +4927,28 @@ page_zip_verify_checksum(
ib_uint32_t crc32 = 0 /* silence bogus warning */; ib_uint32_t crc32 = 0 /* silence bogus warning */;
ib_uint32_t innodb = 0 /* silence bogus warning */; ib_uint32_t innodb = 0 /* silence bogus warning */;
stored = static_cast<ib_uint32_t>(mach_read_from_4( const srv_checksum_algorithm_t curr_algo =
static_cast<const unsigned char*>(data) + FIL_PAGE_SPACE_OR_CHKSUM)); static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm);
#if FIL_PAGE_LSN % 8 if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) {
#error "FIL_PAGE_LSN must be 64 bit aligned" return true;
#endif }
/* Check if page is empty */ bool all_zeroes = true;
if (stored == 0 for (size_t i = 0; i < size; i++) {
&& *reinterpret_cast<const ib_uint64_t*>(static_cast<const char*>( if (static_cast<const byte*>(data)[i] != 0) {
data) all_zeroes = false;
+ FIL_PAGE_LSN) == 0) { break;
/* make sure that the page is really empty */
for (ulint i = 0; i < size; i++) {
if (*((const char*) data + i) != 0) {
return(FALSE);
}
} }
/* Empty page */
return(TRUE);
} }
const srv_checksum_algorithm_t curr_algo = if (all_zeroes) {
static_cast<srv_checksum_algorithm_t>(srv_checksum_algorithm); return true;
if (curr_algo == SRV_CHECKSUM_ALGORITHM_NONE) {
return(TRUE);
} }
stored = static_cast<ib_uint32_t>(mach_read_from_4(
static_cast<const unsigned char*>(data) + FIL_PAGE_SPACE_OR_CHKSUM));
calc = static_cast<ib_uint32_t>(page_zip_calc_checksum( calc = static_cast<ib_uint32_t>(page_zip_calc_checksum(
data, size, curr_algo)); data, size, curr_algo));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment