From 79b65a3591626af98682fe420034773120161343 Mon Sep 17 00:00:00 2001 From: jamcleod Date: Mon, 8 Jan 2024 16:45:54 -0500 Subject: [PATCH] Add error message when volatility profile is empty --- panda/plugins/cosi/volatility_profile/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/panda/plugins/cosi/volatility_profile/src/lib.rs b/panda/plugins/cosi/volatility_profile/src/lib.rs index 8968cb98872..cd606393fca 100644 --- a/panda/plugins/cosi/volatility_profile/src/lib.rs +++ b/panda/plugins/cosi/volatility_profile/src/lib.rs @@ -171,8 +171,12 @@ pub struct VolatilityJson { impl VolatilityJson { pub fn from_compressed_file(filename: impl AsRef) -> VolatilityJson { //pub fn from_compressed_file(filename: std::fs::File) -> VolatilityJson { - let mut f = BufReader::new(File::open(filename).unwrap()); - //let mut f = BufReader::new(filename); + let file = File::open(filename).unwrap(); + if file.metadata().unwrap().len() == 0 { + panic!("cosi volatility profile empty"); + } + + let mut f = BufReader::new(file); let mut decomp = Vec::new(); lzma_rs::xz_decompress(&mut f, &mut decomp).unwrap(); let s = String::from_utf8_lossy(&decomp);