image_index.rs: verify header magic/version

This commit is contained in:
Dietmar Maurer 2019-01-02 13:13:13 +01:00
parent 44b3f62b42
commit a360f6fa2d
1 changed files with 10 additions and 1 deletions

View File

@ -51,13 +51,22 @@ impl <'a> ImageIndexReader<'a> {
let header_size = std::mem::size_of::<ImageIndexHeader>();
// todo: use static assertion when available in rust
if header_size != 4096 { panic!("got unexpected header size"); }
if header_size != 4096 { bail!("got unexpected header size for {:?}", path); }
let mut buffer = vec![0u8; header_size];
file.read_exact(&mut buffer)?;
let header = unsafe { &mut * (buffer.as_ptr() as *mut ImageIndexHeader) };
if header.magic != *b"PROXMOX-IIDX" {
bail!("got unknown magic number for {:?}", path);
}
let version = u32::from_be(header.version);
if version != 1 {
bail!("got unsupported version number ({})", version);
}
let size = u64::from_be(header.size) as usize;
let ctime = u64::from_be(header.ctime);
let chunk_size = u64::from_be(header.chunk_size) as usize;