FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
fix(interchange): confine embedded audio output names (#2956)
Earl Cof554fdcb4f32
diff --git a/crates/interchange/src/comp.rs b/crates/interchange/src/comp.rsindex 2ade96bcc..32c8698f2 100644--- a/crates/interchange/src/comp.rs+++ b/crates/interchange/src/comp.rs@@ -698,7 +698,10 @@ pub(crate) fn to_project(doc: Document, opts: &ImportOptions, report: &mut ReporNone => groups.push((k, vec![i])),}}- let doc_stem = opts.name.clone().unwrap_or_else(|| "Imported".into());+ // This becomes a directory name for embedded AAF/OMF audio. `ImportOptions::name` normally+ // comes from the document filename, where backslashes are ordinary Unix filename characters;+ // `resolve_path` deliberately treats them as separators, so retain only one safe component.+ let doc_stem = safe_path_component(opts.name.as_deref().unwrap_or("Imported"));let mut used_paths = std::collections::HashSet::new();for ((_, path), members) in &groups {let srcs: Vec<&Source> = members.iter().map(|&i| &doc.sources[i]).collect();@@ -788,6 +791,13 @@ pub(crate) fn to_project(doc: Document, opts: &ImportOptions, report: &mut ReporOk((b.finish(), extracted))}+/// A display name used as a generated path component, never a caller-selected path fragment.+fn safe_path_component(name: &str) -> String {+ let safe: String = name.chars().map(|c| if c.is_alphanumeric() || " -_.".contains(c) { c } else { '_' }).collect();+ let safe = safe.trim();+ if safe.is_empty() || matches!(safe, "." | "..") { "Imported".into() } else { safe.into() }+}+fn build_sequence(b: &mut Builder,comp: &Composition,@@ -1004,3 +1014,15 @@ pub(crate) fn ticks_to_units(t: Tick, num: i64, den: i64) -> (i64, bool) {let n = q + if r * 2 >= d { 1 } else { 0 };(n.clamp(i64::MIN as i128, i64::MAX as i128) as i64, r == 0)}++#[cfg(test)]+mod path_tests {+ use super::safe_path_component;++ #[test]+ fn generated_embedded_audio_folder_is_one_safe_component() {+ for (input, expected) in [(r"..\escape", ".._escape"), ("../escape", ".._escape"), ("..", "Imported"), ("", "Imported")] {+ assert_eq!(safe_path_component(input), expected, "{input:?}");+ }+ }+}