From 8f8d3c01398ba931477d608e85111668833553ab Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Tue, 24 Dec 2024 19:30:41 +0000 Subject: [PATCH] block: vhdx: fix checksum calculation The checksum field in the original buffer should be zeroed. The code was zeroing a temporary buffer. That's wrong. Signed-off-by: Wei Liu --- block/src/vhdx/vhdx_header.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/block/src/vhdx/vhdx_header.rs b/block/src/vhdx/vhdx_header.rs index 48967bd78..e1138b587 100644 --- a/block/src/vhdx/vhdx_header.rs +++ b/block/src/vhdx/vhdx_header.rs @@ -457,12 +457,10 @@ impl VhdxHeader { /// corresponding field is made zero. After the calculation, the existing checksum /// is put back to the buffer. pub fn calculate_checksum(buffer: &mut [u8], csum_offset: usize) -> Result { - // Read the checksum into a mutable slice - let csum_buf = &mut buffer[csum_offset..csum_offset + 4]; - // Convert the checksum chunk into a u32 integer - let orig_csum = LittleEndian::read_u32(csum_buf); + // Read the original checksum from the buffer + let orig_csum = LittleEndian::read_u32(&buffer[csum_offset..csum_offset + 4]); // Zero the checksum in the buffer - LittleEndian::write_u32(csum_buf, 0); + LittleEndian::write_u32(&mut buffer[csum_offset..csum_offset + 4], 0); // Calculate the checksum on the resulting buffer let mut crc = crc_any::CRC::crc32c(); crc.digest(&buffer);