From cd8bf1667494070c3a22ab5d63b559a9742b8a1a Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Sat, 18 Jan 2025 23:47:48 -0600 Subject: more stuff --- src/launcher/extract.rs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'src/launcher/extract.rs') 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)] -- cgit v1.2.3-70-g09d2