fix(engine): write every concat list through one writer that refuses control characters

This commit is contained in:
Miguel Angel Simon Sierra
2026-11-18 17:28:50 -05:00
parent 18e31c7263
commit 97d482340a
5 changed files with 34 additions and 11 deletions
+1 -1
View File
@@ -198,7 +198,7 @@ export {
} from "./services/screenshotService.js";
// ── Encoding ───────────────────────────────────────────────────────────────────
export { concatListInputArgs } from "@hyperframes/parsers/ff-binaries";
export { concatListInputArgs, concatListText } from "@hyperframes/parsers/ff-binaries";
export {
buildEncoderArgs,
encodeFramesFromDir,
+8 -3
View File
@@ -50,7 +50,7 @@ import { appendVp9CpuUsedArg } from "./vp9Options.js";
import { appendSoftwareEncoderThreadsArg } from "./softwareEncoderThreads.js";
import { appendRenderProvenanceArgs } from "../utils/renderProvenance.js";
import { createStagingDir } from "@hyperframes/core/atomic-file";
import { concatListInputArgs } from "@hyperframes/parsers/ff-binaries";
import { concatListInputArgs, concatListText } from "@hyperframes/parsers/ff-binaries";
export type { EncoderOptions, EncodeResult, MuxResult } from "./chunkEncoder.types.js";
@@ -693,7 +693,7 @@ let concatListSeq = 0;
function writeConcatList(dir: string, inputPaths: readonly string[]): string {
concatListSeq += 1;
const listPath = join(dir, `concat-list-${process.pid}-${concatListSeq}.txt`);
const body = inputPaths.map((p) => `file '${resolve(p).replace(/'/g, "'\\''")}'`).join("\n");
const body = concatListText(inputPaths.map((p) => resolve(p)));
writeFileSync(listPath, body, "utf-8");
return listPath;
}
@@ -721,7 +721,12 @@ export async function concatVideoFiles(
// get their own chunk directory but can share an output directory.
// The list is left on disk deliberately: it is removed with the work dir,
// and `--debug` keeps both so a bad concat can be reproduced from its list.
const listPath = writeConcatList(dirname(firstInput), inputPaths);
let listPath: string;
try {
listPath = writeConcatList(dirname(firstInput), inputPaths);
} catch (error) {
return { success: false, error: (error as Error).message, externalInterruption: false };
}
const encodeTimeout = config?.ffmpegEncodeTimeout ?? DEFAULT_CONFIG.ffmpegEncodeTimeout;
const result = await runFfmpeg(buildConcatArgs(listPath, outputPath), {
signal,
+17
View File
@@ -249,6 +249,23 @@ export function clearFfBinaryLookupCache(): void {
skippedX86Binaries.clear();
}
const holdsControlCharacter = (text: string) =>
[...text].some((char) => char < " " || char === "\u007f");
/** One `file` entry per path; a control character (a line break starts a list line) is refused. */
export function concatListText(paths: readonly string[]): string {
return paths
.map((path) => {
if (holdsControlCharacter(path)) {
throw new Error(
`A file to join holds a control character in its path: ${JSON.stringify(path)}`,
);
}
return `file '${path.replace(/'/g, "'\\''")}'\n`;
})
.join("");
}
/**
* Concat input for a list HyperFrames wrote: entries open only as local mov, matroska or concat
* files (an ffconcat entry is followed in safe mode), and `-xerror` fails at a refused entry.
@@ -39,6 +39,7 @@ import {
appendRateCapArgs,
appendRenderProvenanceArgs,
concatListInputArgs,
concatListText,
describeFfmpegFailure,
getEncoderPreset,
MIXED_AUDIO_FILENAME,
@@ -393,10 +394,8 @@ function concatDemuxerInput(
workDir: string,
fpsArg: string,
): string[] {
// ffmpeg's concat list escapes a single quote as `'\''`.
const listPath = join(workDir, "concat-list.txt");
const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
writeFileSync(listPath, `${body}\n`, "utf-8");
writeFileSync(listPath, concatListText(chunkPaths), "utf-8");
return ["-r", fpsArg, ...concatListInputArgs(listPath)];
}
@@ -7,6 +7,7 @@ import { hdrToSdrToneMapFilter, type PreviewProxyBox } from "@hyperframes/core";
import { previewToken } from "@hyperframes/core/preview-proof";
import {
concatListInputArgs,
concatListText,
findFfBinary,
followFfmpegProgress,
} from "@hyperframes/parsers/ff-binaries";
@@ -659,10 +660,11 @@ async function encodeInChunks(
try {
writeFileSync(
listPath,
pieces
.map((piece) => (JOIN_FROM_CACHE_FOLDER ? basename(piece) : piece.replace(/\\/g, "/")))
.map((piece) => `file '${piece.replace(/'/g, "'\\''")}'\n`)
.join(""),
concatListText(
pieces.map((piece) =>
JOIN_FROM_CACHE_FOLDER ? basename(piece) : piece.replace(/\\/g, "/"),
),
),
);
await concat(listPath, tempPath);
} finally {