diff --git a/packages/cli/src/media-use/lib/grade-analyzer.mjs b/packages/cli/src/media-use/lib/grade-analyzer.mjs index 5a5b0d1f79..00fc64fc8c 100644 --- a/packages/cli/src/media-use/lib/grade-analyzer.mjs +++ b/packages/cli/src/media-use/lib/grade-analyzer.mjs @@ -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 = diff --git a/packages/cli/src/media-use/lib/grade-analyzer.test.mjs b/packages/cli/src/media-use/lib/grade-analyzer.test.mjs index 0a649029d6..b620cba964 100644 --- a/packages/cli/src/media-use/lib/grade-analyzer.test.mjs +++ b/packages/cli/src/media-use/lib/grade-analyzer.test.mjs @@ -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/, + ); +}); diff --git a/packages/cli/src/media-use/lib/literal-media-input.mjs b/packages/cli/src/media-use/lib/literal-media-input.mjs new file mode 100644 index 0000000000..0f190cb089 --- /dev/null +++ b/packages/cli/src/media-use/lib/literal-media-input.mjs @@ -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.", + ); +} diff --git a/packages/cli/src/media-use/lib/probe.mjs b/packages/cli/src/media-use/lib/probe.mjs index a700f795d1..0d2f172828 100644 --- a/packages/cli/src/media-use/lib/probe.mjs +++ b/packages/cli/src/media-use/lib/probe.mjs @@ -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( diff --git a/packages/cli/src/media-use/lib/probe.test.mjs b/packages/cli/src/media-use/lib/probe.test.mjs index 194e6009cb..fbd47cddee 100644 --- a/packages/cli/src/media-use/lib/probe.test.mjs +++ b/packages/cli/src/media-use/lib/probe.test.mjs @@ -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); +}); diff --git a/scripts/generate-skill-module-copies.mjs b/scripts/generate-skill-module-copies.mjs index 437b6b3bed..61409ac72a 100644 --- a/scripts/generate-skill-module-copies.mjs +++ b/scripts/generate-skill-module-copies.mjs @@ -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", [ diff --git a/skills-manifest.json b/skills-manifest.json index e6277c179e..36204da41b 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -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", diff --git a/skills/figma/scripts/lib/literal-media-input.mjs b/skills/figma/scripts/lib/literal-media-input.mjs new file mode 100644 index 0000000000..0f190cb089 --- /dev/null +++ b/skills/figma/scripts/lib/literal-media-input.mjs @@ -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.", + ); +} diff --git a/skills/figma/scripts/verify-motion.mjs b/skills/figma/scripts/verify-motion.mjs index e628b366e3..33215cde9d 100644 --- a/skills/figma/scripts/verify-motion.mjs +++ b/skills/figma/scripts/verify-motion.mjs @@ -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")); diff --git a/skills/hyperframes/scripts/bake-basemap.mjs b/skills/hyperframes/scripts/bake-basemap.mjs index b8a9b8888d..03d5942bb4 100644 --- a/skills/hyperframes/scripts/bake-basemap.mjs +++ b/skills/hyperframes/scripts/bake-basemap.mjs @@ -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. diff --git a/skills/hyperframes/scripts/lib/literal-media-input.mjs b/skills/hyperframes/scripts/lib/literal-media-input.mjs new file mode 100644 index 0000000000..0f190cb089 --- /dev/null +++ b/skills/hyperframes/scripts/lib/literal-media-input.mjs @@ -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.", + ); +} diff --git a/skills/hyperframes/scripts/literal-media-paths.test.mjs b/skills/hyperframes/scripts/literal-media-paths.test.mjs new file mode 100644 index 0000000000..08d840a587 --- /dev/null +++ b/skills/hyperframes/scripts/literal-media-paths.test.mjs @@ -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); +}); diff --git a/skills/hyperframes/scripts/locate.mjs b/skills/hyperframes/scripts/locate.mjs index eb7100d35c..4132d9432e 100644 --- a/skills/hyperframes/scripts/locate.mjs +++ b/skills/hyperframes/scripts/locate.mjs @@ -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 || "."; diff --git a/skills/media-use/audio/scripts/carve.mjs b/skills/media-use/audio/scripts/carve.mjs index ee2832019f..9fda53b53e 100644 --- a/skills/media-use/audio/scripts/carve.mjs +++ b/skills/media-use/audio/scripts/carve.mjs @@ -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", [ diff --git a/skills/media-use/audio/scripts/lib/recording.mjs b/skills/media-use/audio/scripts/lib/recording.mjs index e8253b5b5e..7470037bde 100644 --- a/skills/media-use/audio/scripts/lib/recording.mjs +++ b/skills/media-use/audio/scripts/lib/recording.mjs @@ -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}` }; diff --git a/skills/media-use/scripts/dither.mjs b/skills/media-use/scripts/dither.mjs index 6b50bdc3db..794790d08d 100644 --- a/skills/media-use/scripts/dither.mjs +++ b/skills/media-use/scripts/dither.mjs @@ -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"); diff --git a/skills/media-use/scripts/lib/literal-media-input.mjs b/skills/media-use/scripts/lib/literal-media-input.mjs new file mode 100644 index 0000000000..0f190cb089 --- /dev/null +++ b/skills/media-use/scripts/lib/literal-media-input.mjs @@ -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.", + ); +} diff --git a/skills/media-use/scripts/transcript-cut.mjs b/skills/media-use/scripts/transcript-cut.mjs index b62e33eeeb..7092fcfa12 100644 --- a/skills/media-use/scripts/transcript-cut.mjs +++ b/skills/media-use/scripts/transcript-cut.mjs @@ -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);