mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(parsers): media paths resolve to absolute paths, and only http(s) skip the literal-name check (#8740)
* fix(parsers): media paths resolve to absolute paths, and only http(s) skip the literal-name check * chore(skills): regenerate the skills manifest for the literal-name check * chore(parsers): raise the unpacked size budget to what the absolute resolver measures * chore(skills): regenerate the skills manifest after merging main * chore(skills): regenerate the skills manifest after merging main * chore(skills): regenerate the skills manifest after merging main
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
// 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 WILDCARD_MAKES_ANY_PERCENT_A_PATTERN = /[*?[{]/;
|
||||
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
|
||||
const FORWARDED = /^https?:/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);
|
||||
const pattern =
|
||||
PATTERN_IMAGE2_EXPANDS.test(input) ||
|
||||
(input.includes("%") && WILDCARD_MAKES_ANY_PERCENT_A_PATTERN.test(input));
|
||||
if (!local || !pattern) return;
|
||||
if (FORWARDED.test(input) || !pattern) return;
|
||||
throw new Error(
|
||||
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
|
||||
'with or without digits between, or a "%" and a wildcard (*, ?, [ or {) anywhere in the path, would make ffmpeg ' +
|
||||
|
||||
@@ -2,7 +2,7 @@ import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join, posix, win32 } from "node:path";
|
||||
import { isAbsolute, join, posix, resolve, win32 } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import {
|
||||
collectSubCompositionSrcs,
|
||||
@@ -143,6 +143,21 @@ describe("collectSubCompositionSrcs", () => {
|
||||
|
||||
// The browser clamps `..` at the origin root; path.join does not. One resolver must serve lint and render.
|
||||
describe("resolveProjectRelativeSrc — the one src resolver for lint and render", () => {
|
||||
// fails without the fix: with "." as the base the join stayed relative, so a src such as concat:a.wav|b.wav led
|
||||
// the path ffmpeg was handed, and ffmpeg read it as its concat protocol instead of a project file.
|
||||
it("returns an absolute path whatever base the caller passed", () => {
|
||||
for (const base of [".", "./", ""])
|
||||
for (const src of [
|
||||
"concat:a.wav|b.wav",
|
||||
"subfile,,start,0,end,1,,:clip.mp4",
|
||||
"assets/clip.mp4",
|
||||
]) {
|
||||
const path = resolveProjectRelativeSrc(src, base, base && `${base}/compiled`);
|
||||
expect(isAbsolute(path)).toBe(true);
|
||||
expect(path.startsWith(resolve(base))).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
let tmp: string;
|
||||
|
||||
beforeAll(() => {
|
||||
|
||||
@@ -230,9 +230,11 @@ function gitBashFile(src: string): string | undefined {
|
||||
/** Resolves a media `src` like a browser URL (`..` clamps at the project root); a miss returns the base-dir join. */
|
||||
export function resolveProjectRelativeSrc(
|
||||
src: string,
|
||||
baseDir: string,
|
||||
compiledDir?: string,
|
||||
relativeOrAbsoluteBase: string,
|
||||
relativeOrAbsoluteCompiled?: string,
|
||||
): string {
|
||||
const baseDir = resolve(relativeOrAbsoluteBase);
|
||||
const compiledDir = relativeOrAbsoluteCompiled && resolve(relativeOrAbsoluteCompiled);
|
||||
const cleanSrc = fileUrlAsPath(cleanAssetUrl(src));
|
||||
|
||||
// A leading slash is an origin-root URL served from the project root, unless the absolute path exists.
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { assertLiteralMediaInput, assertLiteralMediaOutput } from "./literalMediaInput.js";
|
||||
|
||||
describe("assertLiteralMediaInput", () => {
|
||||
// fails without the fix: every scheme but file: skipped the check, as if another check had vetted it.
|
||||
it("checks a scheme-led name as a local one; only http and https are left to the caller", () => {
|
||||
for (const path of [
|
||||
"concat:/a/b%d.png",
|
||||
"subfile,,start,0,end,0,,:/a/b%d.png",
|
||||
"data:/a%d.png",
|
||||
]) {
|
||||
expect(() => assertLiteralMediaInput(path)).toThrow(/pattern of other files/);
|
||||
expect(() => assertLiteralMediaOutput(path)).toThrow(/pattern of other files/);
|
||||
}
|
||||
for (const path of [
|
||||
"https://cdn.example/a%2d.png",
|
||||
"HTTP://cdn.example/a%2d.png",
|
||||
"/a/clip.mp4",
|
||||
])
|
||||
expect(() => assertLiteralMediaInput(path)).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,12 @@
|
||||
const PATTERN_IMAGE2_EXPANDS = /%\d*[d%*?[\]{}]/;
|
||||
const WILDCARD_MAKES_ANY_PERCENT_A_PATTERN = /[*?[{]/;
|
||||
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
|
||||
const FORWARDED = /^https?:/i;
|
||||
|
||||
function refusePattern(path: string, use: "read" | "write"): void {
|
||||
const local = !URL_SCHEME.test(path) || /^file:/i.test(path);
|
||||
const pattern =
|
||||
PATTERN_IMAGE2_EXPANDS.test(path) ||
|
||||
(path.includes("%") && WILDCARD_MAKES_ANY_PERCENT_A_PATTERN.test(path));
|
||||
if (!local || !pattern) return;
|
||||
if (FORWARDED.test(path) || !pattern) return;
|
||||
throw new Error(
|
||||
`[FFmpeg] refused media path "${path.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
|
||||
`with or without digits between, or a "%" and a wildcard (*, ?, [ or {) anywhere in the path, would make ffmpeg ` +
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
"source": "heygen-com/hyperframes",
|
||||
"skills": {
|
||||
"figma": {
|
||||
"hash": "b1facb484ca64802",
|
||||
"hash": "aee1018803b57ea3",
|
||||
"files": 4
|
||||
},
|
||||
"hyperframes": {
|
||||
"hash": "1ebf5a311a4d1ed7",
|
||||
"hash": "7b9108a831fc740a",
|
||||
"files": 85
|
||||
},
|
||||
"hyperframes-cli": {
|
||||
@@ -18,7 +18,7 @@
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
"hash": "ff2fa3c4eb8a7bc1",
|
||||
"hash": "fff20d7c6efcc737",
|
||||
"files": 135
|
||||
},
|
||||
"remotion-to-hyperframes": {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
// 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 WILDCARD_MAKES_ANY_PERCENT_A_PATTERN = /[*?[{]/;
|
||||
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
|
||||
const FORWARDED = /^https?:/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);
|
||||
const pattern =
|
||||
PATTERN_IMAGE2_EXPANDS.test(input) ||
|
||||
(input.includes("%") && WILDCARD_MAKES_ANY_PERCENT_A_PATTERN.test(input));
|
||||
if (!local || !pattern) return;
|
||||
if (FORWARDED.test(input) || !pattern) return;
|
||||
throw new Error(
|
||||
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
|
||||
'with or without digits between, or a "%" and a wildcard (*, ?, [ or {) anywhere in the path, would make ffmpeg ' +
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
// 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 WILDCARD_MAKES_ANY_PERCENT_A_PATTERN = /[*?[{]/;
|
||||
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
|
||||
const FORWARDED = /^https?:/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);
|
||||
const pattern =
|
||||
PATTERN_IMAGE2_EXPANDS.test(input) ||
|
||||
(input.includes("%") && WILDCARD_MAKES_ANY_PERCENT_A_PATTERN.test(input));
|
||||
if (!local || !pattern) return;
|
||||
if (FORWARDED.test(input) || !pattern) return;
|
||||
throw new Error(
|
||||
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
|
||||
'with or without digits between, or a "%" and a wildcard (*, ?, [ or {) anywhere in the path, would make ffmpeg ' +
|
||||
|
||||
@@ -35,7 +35,11 @@ test("the standalone check refuses exactly what the parsers check refuses", () =
|
||||
script("skills/hyperframes/scripts/lib/literal-media-input.mjs"),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of ["PATTERN_IMAGE2_EXPANDS", "WILDCARD_MAKES_ANY_PERCENT_A_PATTERN"]) {
|
||||
for (const name of [
|
||||
"PATTERN_IMAGE2_EXPANDS",
|
||||
"WILDCARD_MAKES_ANY_PERCENT_A_PATTERN",
|
||||
"FORWARDED",
|
||||
]) {
|
||||
const pattern = (text) => new RegExp(`const ${name} = (.+);`).exec(text)?.[1];
|
||||
assert.ok(pattern(source), name);
|
||||
assert.equal(pattern(ours), pattern(source), name);
|
||||
@@ -46,10 +50,19 @@ test("the standalone check refuses exactly what the parsers check refuses", () =
|
||||
"file:/a/b%%.png",
|
||||
"/a/credentials.json%a{.xface",
|
||||
"/a/x{/y%a.png",
|
||||
"concat:/a/b%d.png",
|
||||
"subfile,,start,0,end,0,,:/a/b%d.png",
|
||||
"data:/a%d.png",
|
||||
"crypto:/a/b%d.png",
|
||||
]) {
|
||||
assert.throws(() => assertLiteralMediaPath(path), PATTERN);
|
||||
}
|
||||
for (const path of ["/a/100% done.mp4", "/a/x{y}.png", "https://cdn.example/a%2d.png"]) {
|
||||
for (const path of [
|
||||
"/a/100% done.mp4",
|
||||
"/a/x{y}.png",
|
||||
"https://cdn.example/a%2d.png",
|
||||
"http://cdn.example/a%2d.png",
|
||||
]) {
|
||||
assert.doesNotThrow(() => assertLiteralMediaPath(path));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
// 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 WILDCARD_MAKES_ANY_PERCENT_A_PATTERN = /[*?[{]/;
|
||||
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
|
||||
const FORWARDED = /^https?:/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);
|
||||
const pattern =
|
||||
PATTERN_IMAGE2_EXPANDS.test(input) ||
|
||||
(input.includes("%") && WILDCARD_MAKES_ANY_PERCENT_A_PATTERN.test(input));
|
||||
if (!local || !pattern) return;
|
||||
if (FORWARDED.test(input) || !pattern) return;
|
||||
throw new Error(
|
||||
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by "d", another "%" or a wildcard, ` +
|
||||
'with or without digits between, or a "%" and a wildcard (*, ?, [ or {) anywhere in the path, would make ffmpeg ' +
|
||||
|
||||
Reference in New Issue
Block a user