GNU bug report logs - #76360
cksum crc broken with VMULL on musl

Previous Next

Package: coreutils;

Reported by: Alyssa Ross <hi <at> alyssa.is>

Date: Mon, 17 Feb 2025 09:27:01 UTC

Severity: normal

Tags: fixed

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 76360 <at> debbugs.gnu.org (full text, mbox):

From: Alyssa Ross <hi <at> alyssa.is>
To: 76360 <at> debbugs.gnu.org
Subject: [PATCH] cksum: fix shift count overflow
Date: Mon, 17 Feb 2025 11:05:49 +0100
This fixes the following warnings when building for a platform where
uint_fast32_t is 32 bits:

src/cksum_vmull.c: In function 'cksum_vmull':
src/cksum_vmull.c:95:69: warning: left shift count >= width of type [-Wshift-count-overflow]
   95 |           xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (crc << 32));
      |                                                                     ^~
src/cksum_vmull.c:196:69: warning: left shift count >= width of type [-Wshift-count-overflow]
  196 |           xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (crc << 32));
      |                                                                     ^~

This resulted in cksum -a crc producing incorrect values on musl.
---
 src/cksum_vmull.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/cksum_vmull.c b/src/cksum_vmull.c
index c6f067584..6a87a21ab 100644
--- a/src/cksum_vmull.c
+++ b/src/cksum_vmull.c
@@ -92,7 +92,7 @@ cksum_vmull (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
           data = bswap_neon (data);
           /* XOR in initial CRC value (for us 0 so no effect), or CRC value
              calculated for previous BUFLEN buffer from fread */
-          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (crc << 32));
+          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 ((uint64_t)crc << 32));
           crc = 0;
           data = veorq_u64 (data, xor_crc);
           data3 = vld1q_u64 ((uint64_t *) (datap + 1));
@@ -193,7 +193,7 @@ cksum_vmull (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out)
         {
           data = vld1q_u64 ((uint64_t *) (datap));
           data = bswap_neon (data);
-          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (crc << 32));
+          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 ((uint64_t)crc << 32));
           crc = 0;
           data = veorq_u64 (data, xor_crc);
           while (bytes_read >= 32)

base-commit: d155be4a22cdc5d271a74c2ae8226c4239ab76ed
-- 
2.47.2





This bug report was last modified 153 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.