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
This commit is contained in:
Pete Zaitcev 2019-02-12 22:08:26 -06:00 committed by Tim Burke
parent 405775cba1
commit 7e97b2f808
2 changed files with 3 additions and 3 deletions

View File

@ -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;

View File

@ -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;
}