test: a concat list refuses paths whose folder name holds a line break

This commit is contained in:
Miguel Angel Simon Sierra
2026-11-18 17:07:14 -05:00
parent b8bb8b3803
commit 18e31c7263
3 changed files with 59 additions and 1 deletions
@@ -1,5 +1,5 @@
import { spawnSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, relative } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
@@ -135,6 +135,26 @@ describe.skipIf(!HAS_FFMPEG)("concat input formats", () => {
expect(made.status, made.stderr.toString()).toBe(0);
}
// fails without the fix: the line break ended the entry and ffmpeg read the rest as list lines.
it("refuses inputs whose folder name holds a line break, before writing a list", async () => {
const folder = join(root, "proj\nfile '/etc/hosts'\n#");
mkdirSync(folder);
makeClip(join(folder, "a.mp4"), 2);
makeClip(join(folder, "b.mp4"), 2);
const result = await concatVideoFiles(
[join(folder, "a.mp4"), join(folder, "b.mp4")],
join(root, "joined.mp4"),
);
expect(result).toEqual({
success: false,
error: expect.stringContaining("control character"),
externalInterruption: false,
});
expect(readdirSync(folder).filter((name) => name.startsWith("concat-list-"))).toEqual([]);
}, 30_000);
function frameCount(path: string): string {
const probe = spawnSync(
getFfprobeBinary(),
+18
View File
@@ -641,3 +641,21 @@ describe.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("concatListInput
expect(run.stderr).toContain("not on whitelist 'file'");
});
});
describe("concatListText", () => {
// fails without the fix: every list writer escaped only the single quote, so a line break started a new list line.
it("writes one quoted entry per path and refuses a path holding a control character", async () => {
const { concatListText } = await importFresh();
expect(concatListText(["/a/it's.mp4", "/b/c.mp4"])).toBe(
"file '/a/it'\\''s.mp4'\nfile '/b/c.mp4'\n",
);
for (const path of [
"/p\nfile '/etc/x.mov'\n#/c.mp4",
"/p\r/c.mp4",
"/p\u0000/c.mp4",
"/p\u007f/c.mp4",
]) {
expect(() => concatListText([path])).toThrow("control character");
}
});
});
@@ -387,6 +387,26 @@ describe("assemble()", () => {
TIMEOUT_MS,
);
// fails without the fix: the line break ended the entry and ffmpeg read the rest as list lines.
it(
"refuses chunk paths whose folder name holds a line break, before writing a list",
async () => {
const chunks: ChunkSliceJson[] = [
{ index: 0, startFrame: 0, endFrame: 5 },
{ index: 1, startFrame: 5, endFrame: 10 },
];
const planDir = buildPlanDir("mp4", chunks, 10, false);
const folder = join(planDir, "chunks\nfile '/etc/hosts'\n#");
mkdirSync(folder);
const chunkPaths = ["0.mp4", "1.mp4"].map((name) => join(folder, name));
for (const path of chunkPaths) writeFileSync(path, "not a video");
await expect(assemble(planDir, chunkPaths, null, join(planDir, "out.mp4"))).rejects.toThrow(
"control character",
);
},
TIMEOUT_MS,
);
it(
"single-chunk render stamps exact r_frame_rate on the output container",
async () => {