mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
1a780eefc9
In MySQL 5.7, it was noticed that files are not portable between big-endian and little-endian processor architectures (such as SPARC and x86), because the original implementation of innodb_checksum_algorithm=crc32 was not byte order agnostic. A byte order agnostic implementation of innodb_checksum_algorithm=crc32 was only added to MySQL 5.7, not backported to 5.6. Consequently, MariaDB Server versions 10.0 and 10.1 only contain the CRC-32C implementation that works incorrectly on big-endian architectures, and MariaDB Server 10.2.2 got the byte-order agnostic CRC-32C implementation from MySQL 5.7. MySQL 5.7 introduced a "legacy crc32" variant that is functionally equivalent to the big-endian version of the original crc32 implementation. Thanks to this variant, old data files can be transferred from big-endian systems to newer versions. Introducing new variants of checksum algorithms (without introducing new names for them, or something on the pages themselves to identify the algorithm) generally is a bad idea, because each checksum algorithm is like a lottery ticket. The more algorithms you try, the more likely it will be for the checksum to match on a corrupted page. So, essentially MySQL 5.7 weakened innodb_checksum_algorithm=crc32, and MariaDB 10.2.2 inherited this weakening. We introduce a build option that together with MDEV-17957 makes innodb_checksum_algorithm=strict_crc32 strict again by only allowing one variant of the checksum to match. WITH_INNODB_BUG_ENDIAN_CRC32: A new cmake option for enabling the bug-compatible "legacy crc32" checksum. This is only enabled on big-endian systems by default, to facilitate an upgrade from MariaDB 10.0 or 10.1. Checked by #ifdef INNODB_BUG_ENDIAN_CRC32. ut_crc32_byte_by_byte: Remove (unused function). legacy_big_endian_checksum: Remove. This variable seems to have unnecessarily complicated the logic. When the weakening is enabled, we must always fall back to the buggy checksum. buf_page_check_crc32(): A helper function to compute one or two CRC-32C variants.
58 lines
2.1 KiB
C
58 lines
2.1 KiB
C
/*****************************************************************************
|
|
|
|
Copyright (c) 2011, 2015, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2016, 2018, MariaDB Corporation.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/ut0crc32.h
|
|
CRC32 implementation
|
|
|
|
Created Aug 10, 2011 Vasil Dimov
|
|
*******************************************************/
|
|
|
|
#ifndef ut0crc32_h
|
|
#define ut0crc32_h
|
|
|
|
#include "univ.i"
|
|
|
|
/********************************************************************//**
|
|
Initializes the data structures used by ut_crc32*(). Does not do any
|
|
allocations, would not hurt if called twice, but would be pointless. */
|
|
void
|
|
ut_crc32_init();
|
|
/*===========*/
|
|
|
|
/********************************************************************//**
|
|
Calculates CRC32.
|
|
@param ptr - data over which to calculate CRC32.
|
|
@param len - data length in bytes.
|
|
@return CRC32 (CRC-32C, using the GF(2) primitive polynomial 0x11EDC6F41,
|
|
or 0x1EDC6F41 without the high-order bit) */
|
|
typedef uint32_t (*ut_crc32_func_t)(const byte* ptr, ulint len);
|
|
|
|
/** Pointer to CRC32 calculation function. */
|
|
extern ut_crc32_func_t ut_crc32;
|
|
|
|
#ifdef INNODB_BUG_ENDIAN_CRC32
|
|
/** Pointer to CRC32 calculation function, which uses big-endian byte order
|
|
when converting byte strings to integers internally. */
|
|
extern ut_crc32_func_t ut_crc32_legacy_big_endian;
|
|
#endif /* INNODB_BUG_ENDIAN_CRC32 */
|
|
|
|
extern const char* ut_crc32_implementation;
|
|
|
|
#endif /* ut0crc32_h */
|