From: Paul Eggert Date: Fri, 17 Jan 2025 18:27:55 +0000 (-0800) Subject: crc-x86_64: better fix for unaligned access X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c89cd7c1b57ebbc1436959c8bff1297215e9d08c;p=gnulib.git crc-x86_64: better fix for unaligned access Avoid undefined behavior in a way that doesn’t require the input buffer to be aligned. From a suggestion by Lasse Collin in: https://lists.gnu.org/r/bug-gnulib/2025-01/msg00148.html * lib/crc-x86_64-pclmul.c (crc32_update_no_xor_pclmul): Since the const void * pointer ‘buf’ might not be aligned, assign it to const __m128i_u * instead of to const __m128i *. * lib/crc.c (crc32_update_no_xor): Remove recently-addeda check for buffer alignment. --- diff --git a/ChangeLog b/ChangeLog index f80d7579c0..3164c1c587 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2025-01-17 Paul Eggert + + crc-x86_64: better fix for unaligned access + Avoid undefined behavior in a way that doesn’t require + the input buffer to be aligned. + From a suggestion by Lasse Collin in: + https://lists.gnu.org/r/bug-gnulib/2025-01/msg00148.html + * lib/crc-x86_64-pclmul.c (crc32_update_no_xor_pclmul): + Since the const void * pointer ‘buf’ might not be aligned, + assign it to const __m128i_u * instead of to const __m128i *. + * lib/crc.c (crc32_update_no_xor): + Remove recently-addeda check for buffer alignment. + 2025-01-17 Pádraig Brady Avoid -Wformat=security failures with --disable-nls diff --git a/lib/crc-x86_64-pclmul.c b/lib/crc-x86_64-pclmul.c index 48f5c7a84c..1650843394 100644 --- a/lib/crc-x86_64-pclmul.c +++ b/lib/crc-x86_64-pclmul.c @@ -32,7 +32,7 @@ __attribute__ ((__target__ ("pclmul,avx"))) uint32_t crc32_update_no_xor_pclmul (uint32_t crc, const void *buf, size_t len) { - const __m128i *data = buf; + const __m128i_u *data = buf; __m128i *datarw; size_t bytes_remaining = len; __m128i in256[4] = { 0 }; diff --git a/lib/crc.c b/lib/crc.c index 57abf27cc3..319a23715b 100644 --- a/lib/crc.c +++ b/lib/crc.c @@ -123,7 +123,7 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len) pclmul_checked = true; } - if (pclmul_enabled && len >= 16 && (intptr_t) buf % 16 == 0) + if (pclmul_enabled && len >= 16) return crc32_update_no_xor_pclmul (crc, buf, len); #endif @@ -205,7 +205,7 @@ crc32_update_no_xor (uint32_t crc, const char *buf, size_t len) pclmul_checked = true; } - if (pclmul_enabled && len >= 16 && (intptr_t) buf % 16 == 0) + if (pclmul_enabled && len >= 16) return crc32_update_no_xor_pclmul (crc, buf, len); #endif