diff options
Diffstat (limited to 'src/launcher/extract.rs')
| -rw-r--r-- | src/launcher/extract.rs | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/launcher/extract.rs b/src/launcher/extract.rs index 206d34f..0a08175 100644 --- a/src/launcher/extract.rs +++ b/src/launcher/extract.rs @@ -7,6 +7,7 @@ use std::path::{Component, Path, PathBuf}; use log::{debug, trace}; use zip::result::ZipError; use zip::ZipArchive; +use crate::util; #[derive(Debug)] pub enum ZipExtractError { @@ -48,27 +49,10 @@ impl Error for ZipExtractError { } fn check_entry_path(name: &str) -> Result<&Path, ZipExtractError> { - let entry_path: &Path = Path::new(name); - - let mut depth = 0usize; - for component in entry_path.components() { - depth = match component { - Component::Prefix(_) | Component::RootDir => - return Err(ZipExtractError::InvalidEntry { - why: "root path component in entry", - name: name.to_owned() - }), - Component::ParentDir => depth.checked_sub(1) - .map_or_else(|| Err(ZipExtractError::InvalidEntry { - why: "entry path escapes extraction root", - name: name.to_owned() - }), |s| Ok(s))?, - Component::Normal(_) => depth + 1, - _ => depth - } - } - - Ok(entry_path) + util::check_path(name).map_err(|e| ZipExtractError::InvalidEntry { + why: e, + name: name.to_owned() + }) } #[cfg(unix)] |
