From 7e97b2f808e1115425eef527899b27528f05af3a Mon Sep 17 00:00:00 2001 From: Pete Zaitcev Date: Tue, 12 Feb 2019 22:08:26 -0600 Subject: [PATCH] Make our alt crc32 more portable Apparently the author of our old crc32 assumed that shifting an int to the right sign-extends, which is not always the case. Result is, building and running make test on s390x fails. The fix is to force a sign-extension using the "xor 0x80; sub 0x80" trick. N.B. This does not cause a compatibility problem, because by a miracle the "broken" crc32_alt was actually computing a stock crc32, same that zlib has. Therefore, if someone, somewhere, ran a Swift cluster on s390x with erasure coding policy, the data in it is already stored with zlib checksums, as we do it now anyway. This fix only permits the tests pass, which used the bad data sample from x86. Change-Id: Ibd5e4e6c02be00540a9648cc7e0f8efda275bf3f Related-Change: Ib5ea2a830c7c23d66bf2ca404a3eb84ad00c5bc5 Related-Bug: 1666320 --- src/erasurecode.c | 3 +-- src/utils/chksum/crc32.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/erasurecode.c b/src/erasurecode.c index dd59ae5..a660588 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -1045,8 +1045,7 @@ int liberasurecode_get_fragment_metadata(char *fragment, } /* Verify metadata checksum */ - if (is_invalid_fragment_header( - (fragment_header_t *) fragment)) { + if (is_invalid_fragment_header((fragment_header_t *) fragment)) { log_error("Invalid fragment header information!"); ret = -EBADHEADER; goto out; diff --git a/src/utils/chksum/crc32.c b/src/utils/chksum/crc32.c index b11dec9..0c46107 100644 --- a/src/utils/chksum/crc32.c +++ b/src/utils/chksum/crc32.c @@ -97,7 +97,8 @@ liberasurecode_crc32_alt(int crc, const void *buf, size_t size) crc = crc ^ ~0U; while (size--) - crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8); + crc = crc32_tab[(crc ^ *p++) & 0xFF] ^ + ((((crc >> 8) & 0x00FFFFFF) ^ 0x00800000) - 0x00800000); return crc ^ ~0U; }