From 77c2625a52c18f3364fe6b91b7466aaaa3d9aac3 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Tue, 24 Dec 2024 17:42:41 -0700 Subject: Fix overflow in checksum --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 3aeb2e7..5b44958 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,8 @@ fn main() { .array_chunks::<4>() .map(|bytes| u32::from_be_bytes(bytes)) // Subtract expected as we're supposed to compute it with that blanked - .fold(0u32, |a,b| a.overflowing_add(b).0) - exp_checksum; + .fold(0u32, |a,b| a.overflowing_add(b).0) + .overflowing_sub(exp_checksum).0; if file_data.len() % 4 != 0 { panic!("Invalid checksum: Uneven number of bytes"); -- cgit 1.4.1