diff --git a/crates/formats/src/export/mod.rs b/crates/formats/src/export/mod.rs index 6b1767e4..bba40729 100644 --- a/crates/formats/src/export/mod.rs +++ b/crates/formats/src/export/mod.rs @@ -968,7 +968,9 @@ pub fn write_files(files: &[ExportedFile], dir: &std::path::Path) -> Result.`; the stem alone is capped at MAX_STEM. + let (stem, ext) = f.name.rsplit_once('.').unwrap_or((&f.name, "")); + if f.name.is_empty() || stem != sanitize_file_stem(stem) || !ext.chars().all(|c| c.is_ascii_alphanumeric()) || f.name.trim_matches('.').is_empty() { return Err(FormatError::Invalid(format!("\"{}\" is not a plain file name", f.name))); } let path = dir.join(&f.name); diff --git a/crates/formats/src/export/tests.rs b/crates/formats/src/export/tests.rs index 3abf005a..83e8cf46 100644 --- a/crates/formats/src/export/tests.rs +++ b/crates/formats/src/export/tests.rs @@ -364,6 +364,18 @@ fn write_files_is_atomic_and_refuses_paths() { std::fs::remove_dir_all(&dir).unwrap(); } +#[test] +fn write_files_accepts_planned_name_with_max_length_stem() { + let fx = Fx::new(&default_channels()); + let files = fx.render_preset("Unreal Engine (Packed)"); + let name = format!("{}.png", sanitize_file_stem(&"a".repeat(250))); + let dir = std::env::temp_dir().join(format!("tc-formats-export-long-{}", std::process::id())); + let long = ExportedFile { name, ..files[0].clone() }; + let paths = write_files(&[long], &dir).unwrap(); + assert_eq!(paths.len(), 1); + std::fs::remove_dir_all(&dir).unwrap(); +} + fn gray_map(file: &str, src: SourceRef) -> MapSpec { MapSpec { file: file.into(), format: FileFormat::Png, bit_depth: 8, channels: vec![(Dest::L, src)] } }