Subject: bug#76360: [PATCH] cksum: fix shift count overflow

From: Alyssa Ross <[email-masked]>
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