From 7eada35b4fbb48e7fe430d1b18dae7d191f84f8e Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 17 Feb 2025 02:27:09 -0800
Subject: [PATCH 2/2] cksum: port to 32-bit uint_fast32_t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/cksum_vmull.c (cksum_vmull): Don’t assume
uint_fast32_t can hold 64 bits.
Problem reported by Alyssa Ross (Bug#76360).

Upstream-Status: Backport [7eada35b4fbb48e7fe430d1b18dae7d191f84f8e]
Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 NEWS              | 3 +++
 src/cksum_vmull.c | 7 +++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/cksum_vmull.c b/src/cksum_vmull.c
index 7611c4244..0ff81e225 100644
--- a/src/cksum_vmull.c
+++ b/src/cksum_vmull.c
@@ -92,7 +92,9 @@ 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));
+
+          uint64_t wcrc = crc;
+          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (wcrc << 32));
           crc = 0;
           data = veorq_u64 (data, xor_crc);
           data3 = vld1q_u64 ((uint64_t *) (datap + 1));
@@ -193,7 +195,8 @@ 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));
+          uint64_t wcrc = crc;
+          xor_crc = vcombine_u64 (vcreate_u64 (0), vcreate_u64 (wcrc << 32));
           crc = 0;
           data = veorq_u64 (data, xor_crc);
           while (bytes_read >= 32)
-- 
2.45.2

