mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
The `read_aligned_block_size()` function used `Vec::from_raw_parts()` incorrectly, causing undefined behavior when deallocating the `Vec<u8>`. One of the safety invariants of `Vec::from_raw_parts()` is that the provided pointer must be allocated with the exact same alignment as `T` (`u8` in this case), but this is clearly not true: `align_of::<u8>()` is 1, but the pointer was allocated with aligment of `blocksize` (typically 512 or greater). Fix this by using the existing `AlignedFile` helper to read the header block when probing the image type. This is slightly less efficient than using `AlignedBuffer` directly, but since this is only called once per disk image at startup, the difference is probably not worth the extra verbosity. Signed-off-by: Daniel Verkamp <drv@meta.com>