]> 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)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 17 Jan 2025 07:01:42 +0000 (23:01 -0800)
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 48fe21b6aa6bd7024cd345f059118858dbd893a1..8a77ff50a8626651861fee4cff60aa8f2108acad 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++)