Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(media): refuse video filter chains that escape their slot

Jareerae99162cd980
diff --git a/engine/crates/relay-media/src/decode.rs b/engine/crates/relay-media/src/decode.rs
index bc419c13..227b9762 100644
--- a/engine/crates/relay-media/src/decode.rs
+++ b/engine/crates/relay-media/src/decode.rs
@@ -168,6 +168,14 @@ impl FfmpegDecoder {
/// dimensions, because the pipe carries raw pixels with no header to say
/// how big a frame is.
pub fn open(path: impl AsRef<Path>, options: &DecodeOptions) -> Result<Self> {
+ // The same slot-escape rule the audio graph enforces: a chain with
+ // `;` or `[..]` is no longer a filter applied to this clip. Video
+ // rode without the guard only because every chain came from our own
+ // catalogue; "validated, not trusted" should not depend on that.
+ if let Some(chain) = &options.filter_chain {
+ crate::audio::validate_chain(chain)?;
+ }
+
let path = path.as_ref();
let (width, height) = match options.size {
Some(size) => size,
@@ -360,6 +368,20 @@ mod tests {
assert!(DecodeOptions::default().filtered("").filter_chain.is_none());
}
+ #[test]
+ fn a_chain_that_escapes_its_slot_is_refused_before_anything_spawns() {
+ for bad in ["hue=s=0;movie=x", "split[a][b]", "a\nb"] {
+ let result = FfmpegDecoder::open(
+ "irrelevant.mp4",
+ &DecodeOptions::default().scaled_to(64, 64).filtered(bad),
+ );
+ assert!(
+ matches!(result, Err(crate::error::Error::InvalidFilterChain { .. })),
+ "{bad:?} should have been refused",
+ );
+ }
+ }
+
#[test]
fn a_missing_ffmpeg_is_a_spawn_error_not_a_panic() {
// Nothing to assert about the happy path without a fixture file, but