Skip to content

Local video editor for coding agents: 42 FFmpeg tools with a machine-readable contract and an MCP server, for Claude Code, Cursor and Codex. Cut, captions, reframe, loudness, platform exports. No cloud, no API keys.

Fix a real filter-graph injection via --font fallback (#108)

Shogo Kajiyama7dfbdc5b30a6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6bdaad..b6008cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,31 @@
(nothing yet)
+## 0.15.3 — fix a real filter-graph injection via --font fallback
+
+Found by the same adversarial pass that produced 0.15.2, this time auditing
+file-path/text escaping instead of colour flags. `overlay.py --font` and
+`graphics.py`'s brand-font fallback both accept a fontconfig family NAME (not
+a file path) and try to resolve it to a concrete file via `default_font_file()`
+(`fc-match`) first -- but that resolution returns `None` whenever `fc-match`
+isn't on `PATH` (true on some real systems, and always true on Windows, per
+`default_font_file()`'s own docstring). When it returns `None`, both tools
+fell back to `font='{args.font}'` with zero escaping, unlike the adjacent
+`text='{escape_drawtext(args.text)}'` one line above it in `overlay.py`.
+Since drawtext options are comma/colon-delimited, a font value like
+`X',drawtext=text=OWNED` doesn't just fail to resolve a font -- the comma
+ends the option (and the whole filter) early and starts an entirely new
+drawtext filter, which actually rendered. Confirmed this is a real, working
+injection (not theoretical): forced the `fc-match`-missing fallback path,
+ran `overlay.py --font "X',drawtext=text=OWNED:fontcolor=yellow..."`, and the
+injected "OWNED" text was actually burnt into the output picture.
+
+Fixed by wrapping both fallback values with the existing `escape_drawtext()`
+helper, matching the already-safe `text=` pattern next to it:
+
+- `overlay.py`'s `font='{args.font}'` fallback (line ~250)
+- `graphics.py`'s `font_opts()` fallback (`font='{font or brand.get(...)}'`)
+
## 0.15.2 — fix a real filter-graph injection via colour flags
Found by adversarial testing: every flag that string-formats a colour straight
diff --git a/docs/contract.md b/docs/contract.md
index e634c96..16d1972 100644
--- a/docs/contract.md
+++ b/docs/contract.md
@@ -21,7 +21,7 @@ The contract is derived from the code that runs, not maintained beside it:
| Field | Meaning | Changes when |
|---|---|---|
| `contract_version` | shape of this document (`1.0`) | a key is renamed, removed or changes meaning |
-| `skill.version` | the npm / package.json version (`0.15.2`) | any release |
+| `skill.version` | the npm / package.json version (`0.15.3`) | any release |
A release that adds a tool or a flag keeps `contract_version`; a breaking change to the
ToolSpec shape bumps it. Consumers pin on `contract_version` and read `skill.version`
@@ -39,7 +39,7 @@ drifting silently.
```json
{
"contract_version": "1.0",
- "skill": {"id": "ffmpeg-skill", "version": "0.15.2", "execution_mode": "local", "kind": "execution",
+ "skill": {"id": "ffmpeg-skill", "version": "0.15.3", "execution_mode": "local", "kind": "execution",
"entrypoints": {"cli": "...", "mcp": "...", "contract": "...", "doctor": "..."},
"not_provided": ["AI reasoning", "decisions", "production plans", "project IR", "approvals", "network access", "transcription engine"]},
"requirements": {"python": ">=3.9 (standard library only)", "ffmpeg": ">=5.0", "ffprobe": ">=5.0"},
diff --git a/package.json b/package.json
index e6874e9..d8e90ac 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ffmpeg-skill",
- "version": "0.15.2",
+ "version": "0.15.3",
"description": "Agent Skill that gives coding agents (Claude Code, Cursor, Codex) a local video editor: 39 FFmpeg tools with a machine-readable contract, contract-derived MCP server, FFmpeg capability detection, probe-first / verify-last workflow. Cut, join, silence removal, fit, captions and karaoke, overlays, motion graphics, HDR to SDR, LUTs, audio clean-up and typed dynamics, sync with drift correction, multicam, loudness, delivery checks, project rendering, batch. No API keys, no cloud, no dependencies.",
"keywords": [
"ffmpeg",
diff --git a/scripts/graphics.py b/scripts/graphics.py
index 3732157..9741bd5 100755
--- a/scripts/graphics.py
+++ b/scripts/graphics.py
@@ -36,7 +36,7 @@ def font_opts(brand: dict, font: Optional[str], font_file: Optional[str]) -> str
resolved = default_font_file(font or brand.get("font", "DejaVu Sans"))
if resolved:
return f"fontfile={escape_filter_path(resolved)}"
- return f"font='{font or brand.get('font', 'DejaVu Sans')}'"
+ return f"font='{escape_drawtext(font or brand.get('font', 'DejaVu Sans'))}'"
def main() -> int:
diff --git a/scripts/overlay.py b/scripts/overlay.py
index e262cda..352cc68 100755
--- a/scripts/overlay.py
+++ b/scripts/overlay.py
@@ -247,7 +247,7 @@ def main() -> int:
if args.font_file:
opts.append(f"fontfile={escape_filter_path(args.font_file)}")
else:
- opts.append(f"font='{args.font}'")
+ opts.append(f"font='{escape_drawtext(args.font)}'")
alpha = alpha_expr(args.opacity, start if start is not None else (0.0 if args.fade > 0 else None),
end if end is not None else ((meta.get("duration") or None) if args.fade > 0 else None), args.fade)
opts.append(f"fontcolor={args.font_color}")
diff --git a/tests/test_all.py b/tests/test_all.py
index 31e97d9..2baef09 100644
--- a/tests/test_all.py
+++ b/tests/test_all.py
@@ -23,8 +23,8 @@ TONES = ("0.6*sin(2*PI*440*t)*gt(sin(2*PI*0.37*t)\\,0.3)+0.4*sin(2*PI*880*t)*gt(
"+0.3*sin(2*PI*220*t)*gt(sin(2*PI*0.21*t+2)\\,0.7)")
-def sh(*cmd, expect_fail=False):
- proc = subprocess.run([str(c) for c in cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8", errors="replace")
+def sh(*cmd, expect_fail=False, env=None):
+ proc = subprocess.run([str(c) for c in cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8", errors="replace", env=env)
if expect_fail:
assert proc.returncode != 0, f"expected failure but succeeded: {cmd}"
return proc
@@ -1594,6 +1594,41 @@ class FFmpegSkillTests(unittest.TestCase):
script("background.py", "--duration", "1", "--width", "640", "--height", "360", "--gradient", "0xff6a00:0x0057ff", "-o", OUT / "colorok4.mp4")
script("overlay.py", self.src, "--text", "hi", "--box-color", "[email protected]", "-o", OUT / "colorok5.mp4")
+ # ---------------------------------------------------------------- font-name filter-graph injection (adversarial)
+ def test_font_flag_escapes_filter_graph_injection_when_unresolved(self):
+ """overlay.py and graphics.py both accept --font as a family NAME, not a file path, and try
+ to resolve it to a concrete file via default_font_file() (fc-match) first -- but that
+ resolution returns None whenever fc-match isn't on PATH (always true on some real systems,
+ e.g. minimal containers and every Windows build), in which case both tools used to fall back
+ to embedding the raw name straight into `font='{args.font}'` with zero escaping. Since
+ drawtext=... options are comma/colon-delimited, a value like "X',drawtext=text=OWNED"
+ doesn't just set an odd font -- the comma ends the font option (and the whole drawtext
+ filter) early and starts an entirely new drawtext filter, which actually rendered (confirmed
+ by rendering the pre-fix code and visually inspecting the burnt-in "OWNED" text). Force the
+ None-fallback path by hiding fc-match from PATH, exactly as it's naturally absent on some
+ real systems, and confirm the built filter graph no longer contains a live breakout."""
+ payload = "X',drawtext=text=OWNED:fontcolor=yellow:fontsize=40:x=10:y=10"
+ stub_dir = OUT / "no_fc_match_path"
+ stub_dir.mkdir(exist_ok=True)
+ for exe in ("ffmpeg", "ffprobe"):
+ real = shutil.which(exe)
+ link = stub_dir / exe
+ if not link.exists():
+ os.symlink(real, link)
+ env = dict(os.environ)
+ env["PATH"] = os.pathsep.join([str(stub_dir), str(Path(sys.executable).parent)])
+
+ out = OUT / "font_inject_overlay.mp4"
+ proc = sh(sys.executable, SCRIPTS / "overlay.py", self.src, "--text", "hello", "--font", payload, "-o", out, env=env)
+ # The escaped payload must show up with a backslash-escaped comma ahead of the injected
+ # "drawtext=text=OWNED" -- proof it stays a literal char inside font='...' instead of
+ # closing the option early and starting a sibling filter.
+ self.assertIn("\\,drawtext=text=OWNED", proc.stderr, "comma must be escaped so it can't break out of font= into a new filter")
+
+ frame = OUT / "font_inject_overlay_frame.png"
+ sh("ffmpeg", "-y", "-hide_banner", "-loglevel", "error", "-i", out, "-ss", "1", "-vframes", "1", frame)
+ self.assertTrue(frame.exists())
+
# ---------------------------------------------------------------- real iPhone regressions (Dolby Vision 8.4 / HLG, VFR, extra tracks)
def test_hdr_source_stays_hdr_through_reencodes(self):
# HLG 10-bit HEVC with audio AND a timecode data track, like an iPhone .mov