From 0b8e75ed16b7c05eafa2dc0d672a7297e8b3ac4a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 2 Jan 2019 18:14:02 +0100 Subject: [PATCH] image_index.rs: verify file size --- src/backup/image_index.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backup/image_index.rs b/src/backup/image_index.rs index d2aed5d6..31e875df 100644 --- a/src/backup/image_index.rs +++ b/src/backup/image_index.rs @@ -73,7 +73,18 @@ impl <'a> ImageIndexReader<'a> { let index_size = ((size + chunk_size - 1)/chunk_size)*32; - // fixme: verify file size ? + let rawfd = file.as_raw_fd(); + + let stat = match nix::sys::stat::fstat(rawfd) { + Ok(stat) => stat, + Err(err) => bail!("fstat {:?} failed - {}", path, err), + }; + + let expected_index_size = ((stat.st_size as usize) - header_size); + if index_size != expected_index_size { + bail!("got unexpected file size for {:?} ({} != {})", + path, index_size, expected_index_size); + } let data = unsafe { nix::sys::mman::mmap( std::ptr::null_mut(),