Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: implement output path validation and add path limits module

Tonho2f2c6a302cbb
diff --git a/src-tauri/omniget-core/src/core/mod.rs b/src-tauri/omniget-core/src/core/mod.rs
index 1b2358f0..14921f7d 100644
--- a/src-tauri/omniget-core/src/core/mod.rs
+++ b/src-tauri/omniget-core/src/core/mod.rs
@@ -10,6 +10,7 @@ pub mod filename;
pub mod hls_downloader;
pub mod http_client;
pub mod hwaccel;
+pub mod log_hook;
pub mod media_processor;
pub mod paths;
pub mod pokemon_names;
diff --git a/src-tauri/src/commands/downloads.rs b/src-tauri/src/commands/downloads.rs
index 9ae18dcc..8f0ada01 100644
--- a/src-tauri/src/commands/downloads.rs
+++ b/src-tauri/src/commands/downloads.rs
@@ -28,6 +28,32 @@ pub fn check_cookie_error() -> bool {
has_error
}
+#[derive(Clone, Serialize)]
+pub struct PathLimitInfo {
+ pub limit: usize,
+ pub current: usize,
+ pub reserve: usize,
+ pub ok: bool,
+}
+
+#[tauri::command]
+pub fn validate_output_path(output_dir: String) -> PathLimitInfo {
+ match crate::core::path_limits::validate_output_dir(&output_dir) {
+ Ok(()) => PathLimitInfo {
+ limit: crate::core::path_limits::MAX_PATH_LEN,
+ current: output_dir.chars().count() + crate::core::path_limits::SEPARATOR_RESERVE,
+ reserve: crate::core::path_limits::MIN_FILENAME_RESERVE,
+ ok: true,
+ },
+ Err(err) => PathLimitInfo {
+ limit: err.limit,
+ current: err.current,
+ reserve: err.reserve,
+ ok: false,
+ },
+ }
+}
+
#[tauri::command]
pub async fn detect_platform(url: String) -> Result<PlatformInfo, String> {
let _timer_start = std::time::Instant::now();
@@ -134,6 +160,13 @@ pub async fn download_from_url(
let _timer_start = std::time::Instant::now();
let platform = Platform::from_url(&url);
+ if let Err(err) = crate::core::path_limits::validate_output_dir(&output_dir) {
+ return Err(format!(
+ "PathTooLong|{}|{}|{}",
+ err.limit, err.current, err.reserve
+ ));
+ }
+
let download_id = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs
index e4712c79..31133a44 100644
--- a/src-tauri/src/core/mod.rs
+++ b/src-tauri/src/core/mod.rs
@@ -16,5 +16,6 @@ pub use omniget_core::core::registry;
pub use omniget_core::core::ytdlp;
pub mod events;
+pub mod path_limits;
pub mod queue;
pub mod url_parser;
diff --git a/src-tauri/src/core/path_limits.rs b/src-tauri/src/core/path_limits.rs
new file mode 100644
index 00000000..0d0a0add
--- /dev/null
+++ b/src-tauri/src/core/path_limits.rs
@@ -0,0 +1,40 @@
+#[cfg(target_os = "windows")]
+pub const MAX_PATH_LEN: usize = 259;
+#[cfg(not(target_os = "windows"))]
+pub const MAX_PATH_LEN: usize = 4095;
+
+pub const MIN_FILENAME_RESERVE: usize = 80;
+
+pub const SEPARATOR_RESERVE: usize = 1;
+
+#[derive(Debug, Clone, Copy)]
+pub struct PathLimitError {
+ pub limit: usize,
+ pub current: usize,
+ pub reserve: usize,
+}
+
+impl std::fmt::Display for PathLimitError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "output path too long for OS limit (path uses {} of {} chars, need {} reserved for filename)",
+ self.current, self.limit, self.reserve
+ )
+ }
+}
+
+impl std::error::Error for PathLimitError {}
+
+pub fn validate_output_dir(output_dir: &str) -> Result<(), PathLimitError> {
+ let current = output_dir.chars().count() + SEPARATOR_RESERVE;
+ let reserve = MIN_FILENAME_RESERVE;
+ if current + reserve > MAX_PATH_LEN {
+ return Err(PathLimitError {
+ limit: MAX_PATH_LEN,
+ current,
+ reserve,
+ });
+ }
+ Ok(())
+}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 9afd2697..3a666699 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -202,6 +202,7 @@ pub fn run() {
commands::diagnostics::get_rate_limit_stats,
commands::downloads::detect_platform,
commands::downloads::check_cookie_error,
+ commands::downloads::validate_output_path,
commands::downloads::get_media_formats,
commands::downloads::prefetch_media_info,
commands::downloads::download_from_url,