From f820dabc314c6661edec9a04ecaff8190f746b9a Mon Sep 17 00:00:00 2001 From: RishabhSaini Date: Thu, 30 Jun 2022 17:18:13 -0400 Subject: [PATCH] embed.rs: Added error check when ISO file incomplete --- src/live/embed.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/live/embed.rs b/src/live/embed.rs index 588f1f52c..e235dc1bf 100644 --- a/src/live/embed.rs +++ b/src/live/embed.rs @@ -346,6 +346,25 @@ impl KargEmbedAreas { ); } + let all_paths: Vec = iso.walk() + .unwrap() + .map(|v| v.unwrap().0) + .collect::>(); + let mut all_files: Vec = Vec::new(); + for path in all_paths { + if path.contains('.'){ + let file = iso.get_path(&path) + .with_context(|| format!("looking up '{:?}'", path))? + .try_into_file()?; + all_files.push(file); + } + } + all_files.sort_by_key(|d| d.address.as_offset()); + if all_files.last().unwrap().address.as_offset() + u64::from(all_files.last().unwrap().length) > iso.as_file()?.metadata()?.len() { + bail!("ISO Image is wrong and can't be modified"); + } + + // writable regions let mut regions = Vec::new(); for loc in info.files {