From: Paul Eggert Date: Fri, 17 Jan 2025 06:58:55 +0000 (-0800) Subject: crc-x86_64: fix unaligned access X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=59146234323977ae8815a6b8aa8c5a81298b19bb;p=gnulib.git crc-x86_64: fix unaligned access Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2025-01/msg00142.html * lib/crc.c (crc32_update_no_xor): Don’t pass unaligned buffer to crc32_update_no_xor_pclmul. No doubt there is a higher performance fix, perhaps involving advancing byte-by-byte along the buffer until we get to an aligned boundary, but at least this should fix the alignment bug. --- diff --git a/ChangeLog b/ChangeLog index 48fe21b6aa..8a77ff50a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-01-16 Paul Eggert + + crc-x86_64: fix unaligned access + Problem reported by Bruno Haible in: + https://lists.gnu.org/r/bug-gnulib/2025-01/msg00142.html + * lib/crc.c (crc32_update_no_xor): Don’t pass unaligned buffer to + crc32_update_no_xor_pclmul. No doubt there is a higher + performance fix, perhaps involving advancing byte-by-byte along + the buffer until we get to an aligned boundary, but at least this + should fix the alignment bug. + 2025-01-16 Bruno Haible getopt-posix: Fix compilation error in C++ mode (regression 2024-09-21). diff --git a/lib/crc.c b/lib/crc.c index 51c72019d8..57abf27cc3 100644 --- a/lib/crc.c +++ b/lib/crc.c @@ -123,8 +123,8 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len) pclmul_checked = true; } - if (pclmul_enabled && len >= 16) - return crc32_update_no_xor_pclmul(crc, buf, len); + if (pclmul_enabled && len >= 16 && (intptr_t) buf % 16 == 0) + return crc32_update_no_xor_pclmul (crc, buf, len); #endif slice_alignment = (len & (-8)); @@ -205,8 +205,8 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len) pclmul_checked = true; } - if (pclmul_enabled && len >= 16) - return crc32_update_no_xor_pclmul(crc, buf, len); + if (pclmul_enabled && len >= 16 && (intptr_t) buf % 16 == 0) + return crc32_update_no_xor_pclmul (crc, buf, len); #endif for (n = 0; n < len; n++)