fix(skills): refuse media paths ffmpeg would read as a pattern in skill scripts (#8661)

* fix(parsers): refuse media paths with digits between a percent sign and a wildcard

* fix(skills): refuse media paths ffmpeg would read as a pattern in skill scripts

* fix(cli): media-use probes refuse paths ffmpeg would read as a pattern
This commit is contained in:
Michael Wang
2026-11-24 08:05:08 +00:00
committed by GitHub
parent add940201e
commit 24f474b960
18 changed files with 216 additions and 6 deletions
@@ -2,6 +2,7 @@
// packages/core/src/mediaGradeAnalyzer.vendoredParity.test.ts guards behavior drift.
import { execFileSync } from "node:child_process";
import { basename, extname } from "node:path";
import { assertLiteralMediaPath } from "./literal-media-input.mjs";
const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp", ".tif", ".tiff"]);
const SAMPLE_FRAMES = 5;
@@ -258,6 +259,7 @@ export function analyzeMediaGrade(
{ ffmpegPath = "ffmpeg", ffprobePath = "ffprobe" } = {},
) {
try {
assertLiteralMediaPath(mediaPath);
const probe = probeMedia(mediaPath, ffprobePath);
const isImage = IMAGE_EXT.has(extname(mediaPath).toLowerCase());
const raw =
@@ -283,3 +283,14 @@ test("does not force middle-gray exposure onto healthy intentional contrast", ()
{ exposure: 0, blacks: 0, whites: 0, temperature: 0, tint: 0 },
);
});
test("grade analysis refuses a file whose name reads as an ffmpeg pattern", () => {
assert.throws(
() =>
analyzeMediaGrade("/project/still%d.png", {
ffmpegPath: "/missing",
ffprobePath: "/missing",
}),
/pattern of other files/,
);
});
@@ -0,0 +1,13 @@
// The standalone twin of assertLiteralMediaInput in packages/parsers/src/literalMediaInput.ts, for inputs and outputs; a test keeps them equal.
const PATTERN_IMAGE2_EXPANDS = /%\d*[d%*?[\]{}]/;
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
/** ffmpeg's image2 reader or writer would use other files, folders included, than the one named. */
export function assertLiteralMediaPath(input) {
const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
throw new Error(
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
"with or without digits between, would make ffmpeg read it as a pattern of other files. Rename the file or folder.",
);
}
+2
View File
@@ -1,6 +1,7 @@
import { execFileSync } from "node:child_process";
import { extname } from "node:path";
import { ffprobeBinary } from "./ff-binaries.mjs";
import { assertLiteralMediaPath } from "./literal-media-input.mjs";
const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".svg", ".ico"]);
const AUDIO_EXT = new Set([".mp3", ".wav", ".ogg", ".m4a", ".aac"]);
@@ -11,6 +12,7 @@ export function probe(filePath) {
const ffprobe = ffprobeBinary();
try {
assertLiteralMediaPath(filePath);
// execFileSync (no shell) so a hostile filename like `"; rm -rf ~; ".png`
// can't break out of the quoting — filePath is passed as a literal argv entry.
const raw = execFileSync(
@@ -219,3 +219,19 @@ test(
}
},
);
test("a file whose name reads as an ffmpeg pattern is never probed", (t) => {
const calls = t.mock.method(childProcess, "execFileSync", () => "{}");
syncBuiltinESMExports();
t.after(() => {
calls.mock.restore();
syncBuiltinESMExports();
});
assert.deepEqual(probe("/project/still%d.png"), {
duration: null,
width: null,
height: null,
codec: null,
});
assert.equal(calls.mock.callCount(), 0);
});
+8
View File
@@ -27,6 +27,14 @@ export const skillModuleCopies = [
"packages/cli/src/media-use/lib/main-module.mjs",
],
],
[
"skills/hyperframes/scripts/lib/literal-media-input.mjs",
[
"skills/media-use/scripts/lib/literal-media-input.mjs",
"skills/figma/scripts/lib/literal-media-input.mjs",
"packages/cli/src/media-use/lib/literal-media-input.mjs",
],
],
[
"skills/hyperframes/scripts/lib/windows-exe-search.mjs",
[
+6 -6
View File
@@ -2,12 +2,12 @@
"source": "heygen-com/hyperframes",
"skills": {
"figma": {
"hash": "a130028ed1fee137",
"files": 3
"hash": "8507ef58a6c8034c",
"files": 4
},
"hyperframes": {
"hash": "58e0e6befb198d57",
"files": 81
"hash": "cd685206b1ec083b",
"files": 83
},
"hyperframes-cli": {
"hash": "36ed7b39fe73ede2",
@@ -18,8 +18,8 @@
"files": 13
},
"media-use": {
"hash": "c0e307853c1496b8",
"files": 131
"hash": "277f0f64db23b1dd",
"files": 132
},
"remotion-to-hyperframes": {
"hash": "f68ca68c0e8b246b",
@@ -0,0 +1,13 @@
// The standalone twin of assertLiteralMediaInput in packages/parsers/src/literalMediaInput.ts, for inputs and outputs; a test keeps them equal.
const PATTERN_IMAGE2_EXPANDS = /%\d*[d%*?[\]{}]/;
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
/** ffmpeg's image2 reader or writer would use other files, folders included, than the one named. */
export function assertLiteralMediaPath(input) {
const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
throw new Error(
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
"with or without digits between, would make ffmpeg read it as a pattern of other files. Rename the file or folder.",
);
}
+2
View File
@@ -26,6 +26,7 @@ import { execFileSync, spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
function arg(name, fallback) {
const i = process.argv.indexOf(`--${name}`);
@@ -39,6 +40,7 @@ if (!reference || !render) {
);
process.exit(2);
}
for (const path of [reference, render]) assertLiteralMediaPath(path);
const crop = arg("crop", null);
const interval = Number(arg("interval", "0.2"));
const minMotion = Number(arg("min-motion-psnr", "15"));
@@ -25,6 +25,7 @@ import { join } from "node:path";
import { mkdirSync, writeFileSync, readdirSync, existsSync } from "node:fs";
import { homedir } from "node:os";
import { spawnSync } from "node:child_process";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
if (process.argv.includes("--help") || process.argv.includes("-h")) {
console.log(`usage: [NAME=..] [STYLE=satellite|dark|light|<{z}/{x}/{y} url>] [CENTER="lng,lat"]
@@ -132,6 +133,7 @@ const TILES =
const OUT = process.env.OUT || process.cwd(); // artifacts → workspace (cwd), NOT the installed skill dir
const framesDir = join(OUT, "frames-" + NAME);
assertLiteralMediaPath(framesDir);
mkdirSync(framesDir, { recursive: true });
// A seeded star field behind the globe, so every bake of the same move is identical.
@@ -0,0 +1,13 @@
// The standalone twin of assertLiteralMediaInput in packages/parsers/src/literalMediaInput.ts, for inputs and outputs; a test keeps them equal.
const PATTERN_IMAGE2_EXPANDS = /%\d*[d%*?[\]{}]/;
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
/** ffmpeg's image2 reader or writer would use other files, folders included, than the one named. */
export function assertLiteralMediaPath(input) {
const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
throw new Error(
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
"with or without digits between, would make ffmpeg read it as a pattern of other files. Rename the file or folder.",
);
}
@@ -0,0 +1,101 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
import { stretchToWav } from "../../media-use/audio/scripts/lib/recording.mjs";
const repo = fileURLToPath(new URL("../../../", import.meta.url));
const script = (path) => join(repo, path);
const PATTERN = /pattern of other files/;
function sandbox(t) {
const dir = mkdtempSync(join(tmpdir(), "skill-literal-media-"));
t.after(() => rmSync(dir, { recursive: true, force: true }));
return dir;
}
// A file whose own name reads as an image2 pattern: the scripts must refuse it, never hand it to ffmpeg.
function patternFile(dir, name = "still%d.png") {
const path = join(dir, name);
writeFileSync(path, "not read");
return path;
}
function runNode(path, args) {
return spawnSync(process.execPath, [script(path), ...args], { encoding: "utf8" });
}
test("the standalone check refuses exactly what the parsers check refuses", () => {
const source = readFileSync(script("packages/parsers/src/literalMediaInput.ts"), "utf8");
const ours = readFileSync(
script("skills/hyperframes/scripts/lib/literal-media-input.mjs"),
"utf8",
);
const pattern = (text) => /const PATTERN_IMAGE2_EXPANDS = (.+);/.exec(text)?.[1];
assert.ok(pattern(source));
assert.equal(pattern(ours), pattern(source));
for (const path of ["/a/b%d.png", "/a/x%3*/c.png", "file:/a/b%%.png"]) {
assert.throws(() => assertLiteralMediaPath(path), PATTERN);
}
for (const path of ["/a/100% done.mp4", "https://cdn.example/a%2d.png"]) {
assert.doesNotThrow(() => assertLiteralMediaPath(path));
}
});
test("dither refuses an input or an output folder that reads as a pattern", (t) => {
const dir = sandbox(t);
const input = patternFile(dir);
const refusedInput = runNode("skills/media-use/scripts/dither.mjs", [
...["--input", input, "--out", join(dir, "out.png"), "--json"],
]);
assert.match(refusedInput.stdout + refusedInput.stderr, PATTERN);
const plain = join(dir, "plain.png");
writeFileSync(plain, "not read");
const refusedOut = runNode("skills/media-use/scripts/dither.mjs", [
...["--input", plain, "--out", join(dir, "o%03d", "out.png"), "--json"],
]);
assert.match(refusedOut.stdout + refusedOut.stderr, PATTERN);
});
test("transcript-cut refuses an input or --out that reads as a pattern", (t) => {
const dir = sandbox(t);
const transcript = join(dir, "transcript.json");
writeFileSync(transcript, JSON.stringify({ words: [{ text: "tone", start: 0, end: 6 }] }));
const cut = (input, out) =>
runNode("skills/media-use/scripts/transcript-cut.mjs", [
...["--input", input, "--transcript", transcript, "--keep", "0-1", "--out", out],
]);
const plain = join(dir, "plain.mp4");
writeFileSync(plain, "not read");
const refusedInput = cut(patternFile(dir, "clip%d.mp4"), join(dir, "out.mp4"));
assert.match(refusedInput.stdout + refusedInput.stderr, PATTERN);
const refusedOut = cut(plain, join(dir, "out%d.mp4"));
assert.match(refusedOut.stdout + refusedOut.stderr, PATTERN);
});
test("locate and verify-motion refuse an image or video that reads as a pattern", (t) => {
const dir = sandbox(t);
const located = runNode("skills/hyperframes/scripts/locate.mjs", [
...["overlay", patternFile(dir), "--out", join(dir, "grid")],
]);
assert.match(located.stdout + located.stderr, PATTERN);
const plain = join(dir, "plain.mp4");
writeFileSync(plain, "not read");
const verified = runNode("skills/figma/scripts/verify-motion.mjs", [
...["--reference", patternFile(dir, "ref%d.mp4"), "--render", plain],
]);
assert.match(verified.stdout + verified.stderr, PATTERN);
});
test("a recording that reads as a pattern is refused with a reason", (t) => {
const dir = sandbox(t);
const made = stretchToWav(patternFile(dir, "take%d.wav"), join(dir, "out.wav"));
assert.equal(made.ok, false);
assert.match(made.error, PATTERN);
});
+2
View File
@@ -23,6 +23,7 @@
import "./lib/windows-exe-search.mjs";
import { execFileSync } from "node:child_process";
import { existsSync, mkdirSync } from "node:fs";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
const N1 = 9,
PAD1 = 0.4; // stage 1: strips per axis, padding in STRIP units
@@ -102,6 +103,7 @@ const opt = {};
for (let i = 0; i < rest.length; i++)
if (rest[i].startsWith("--")) opt[rest[i].slice(2)] = rest[i + 1];
const img = pos[0];
for (const path of [img, opt.out]) if (path) assertLiteralMediaPath(path);
if (cmd === "overlay") {
const dir = opt.out || ".";
+2
View File
@@ -29,6 +29,7 @@ import { readFileSync, writeFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import * as carveApi from "./lib/audio-carve.mjs";
import { isMainModule } from "./lib/main-module.mjs";
import { assertLiteralMediaPath } from "../../scripts/lib/literal-media-input.mjs";
/** Sample rate the analysis runs at. Matches Studio's own decode rate, so the
* bands and envelopes come out the same either way. */
@@ -173,6 +174,7 @@ export function groupSourceRefusal(voices, bed, members) {
function decode(path) {
let raw;
try {
assertLiteralMediaPath(path);
raw = execFileSync(
"ffmpeg",
[
@@ -1,6 +1,7 @@
// recording.mjs — the person's own voice recording as a voice line: converted to the engine's wav,
// time-stretched by `speed` with the pitch kept, with word timings scaled to match.
import "../../../scripts/lib/windows-exe-search.mjs";
import { assertLiteralMediaPath } from "../../../scripts/lib/literal-media-input.mjs";
import { spawnSync } from "node:child_process";
import { existsSync, mkdirSync, statSync } from "node:fs";
import { dirname } from "node:path";
@@ -74,6 +75,11 @@ function probeFormat(src) {
/** src -> 44.1k mono wav at wavAbs, played `speed` times faster. Returns { ok, error? }. */
export function stretchToWav(src, wavAbs, speed = 1) {
try {
assertLiteralMediaPath(src);
} catch (error) {
return { ok: false, error: error.message };
}
const stat = statSync(src, { throwIfNoEntry: false });
if (!stat) return { ok: false, error: `recording not found: ${src}` };
if (!stat.isFile()) return { ok: false, error: `recording is not a file: ${src}` };
+2
View File
@@ -7,6 +7,7 @@ import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync } from "node:fs"
import { dirname, extname, join, resolve } from "node:path";
import { text } from "node:stream/consumers";
import { parseArgs } from "node:util";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
import {
ERROR_DIFFUSION_ALGORITHMS,
applyErrorDiffusionRgba,
@@ -74,6 +75,7 @@ async function run() {
if (!args.input || !args.out) throw new Error("--input and --out are required");
const inputPath = resolve(args.input);
const outPath = resolve(args.out);
for (const path of [inputPath, outPath]) assertLiteralMediaPath(path);
if (!existsSync(inputPath)) throw new Error(`input file not found: ${inputPath}`);
if (inputPath === outPath) throw new Error("--out must differ from --input");
@@ -0,0 +1,13 @@
// The standalone twin of assertLiteralMediaInput in packages/parsers/src/literalMediaInput.ts, for inputs and outputs; a test keeps them equal.
const PATTERN_IMAGE2_EXPANDS = /%\d*[d%*?[\]{}]/;
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
/** ffmpeg's image2 reader or writer would use other files, folders included, than the one named. */
export function assertLiteralMediaPath(input) {
const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
throw new Error(
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
"with or without digits between, would make ffmpeg read it as a pattern of other files. Rename the file or folder.",
);
}
@@ -7,6 +7,7 @@ import { tmpdir } from "node:os";
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
import { parseArgs } from "node:util";
import { compileCutList } from "./lib/cutlist.mjs";
import { assertLiteralMediaPath } from "./lib/literal-media-input.mjs";
import { ownFolder } from "./lib/manifest.mjs";
import { fadeFilterFor } from "./lib/transcriptCutFade.mjs";
import { track } from "./lib/telemetry.mjs";
@@ -89,6 +90,7 @@ function run() {
const inputPath = resolve(args.input);
const outPath = resolve(args.out);
for (const path of [inputPath, outPath]) assertLiteralMediaPath(path);
// An --out inside the project (the folder this runs in) is written only into its real folders.
const rel = relative(process.cwd(), dirname(outPath));
const outsideProject = rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel);