diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sleep_file.rs | 16 | ||||
-rw-r--r-- | src/sleep_register.rs | 7 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/sleep_file.rs b/src/sleep_file.rs index 71e95ba..90e08c4 100644 --- a/src/sleep_file.rs +++ b/src/sleep_file.rs @@ -1,6 +1,6 @@ use std::io::prelude::*; -use std::io::SeekFrom; +use std::os::unix::fs::FileExt; use std::path::Path; use std::fs::File; use integer_encoding::FixedInt; @@ -139,9 +139,10 @@ impl SleepStorage for SleepFile { bail!("Tried to read beyond end of SLEEP file"); } let mut entry = vec![0; entry_size]; - self.file - .seek(SeekFrom::Start(32 + (entry_size as u64) * index))?; - self.file.read_exact(&mut entry)?; + let got = self.file.read_at(&mut entry, 32 + (entry_size as u64) * index)?; + if got != entry.len() { + bail!("Short file read"); + } Ok(entry) } @@ -150,9 +151,10 @@ impl SleepStorage for SleepFile { if data.len() != self.entry_size as usize { bail!("Tried to write mis-sized data"); } - self.file - .seek(SeekFrom::Start(32 + (self.entry_size as u64) * index))?; - self.file.write_all(&data)?; + let put = self.file.write_at(&data, 32 + (self.entry_size as u64) * index)?; + if put != data.len() { + bail!("Short file write"); + } Ok(()) } diff --git a/src/sleep_register.rs b/src/sleep_register.rs index 3e1c48e..276e4c9 100644 --- a/src/sleep_register.rs +++ b/src/sleep_register.rs @@ -3,6 +3,7 @@ use std::io::prelude::*; use std::fs::File; use std::path::{Path, PathBuf}; use std::io::SeekFrom; +use std::os::unix::fs::FileExt; use integer_encoding::FixedInt; use std::fs::OpenOptions; use crypto::blake2b::Blake2b; @@ -412,8 +413,10 @@ impl HyperRegister for SleepDirRegister { // Read chunk let mut data = vec![0; data_len as usize]; - data_file.seek(SeekFrom::Start(offset))?; - data_file.read_exact(&mut data)?; + let got = data_file.read_at(&mut data, offset)?; + if got != data.len() { + bail!("Short file read"); + } // TODO: check the hash? separate function? Ok(data) |