mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-08 05:45:21 +00:00
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 <liuwe@microsoft.com>
This commit is contained in:
parent
408467a05f
commit
8f8d3c0139
@ -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<u32> {
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user