]> Savannah Git Hosting - gnulib.git/commitdiff
crc-x86_64: fix unaligned access
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 Jan 2025 06:58:55 +0000 (22:58 -0800)
committerBruno Haible <bruno@clisp.org>
Sat, 18 Jan 2025 08:17:41 +0000 (09:17 +0100)
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.

ChangeLog
lib/crc.c

index 8f2367e2e4b5d6a97d51cc9582f2db5af41d03d6..f1a42b0f98d1b867ae09c26ba56cf5c0fa6297f0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-01-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <bruno@clisp.org>
 
        getopt-posix: Fix compilation error in C++ mode (regression 2024-09-21).
index 51c72019d83309b0a65e7902a9e3e683cd0f03d7..57abf27cc3160d750bfc267236d23822710f64f4 100644 (file)
--- 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++)