From 18e31c726352ec3e6b7db08e6d261a7702ec8dfb Mon Sep 17 00:00:00 2001 From: Miguel Angel Simon Sierra Date: Wed, 18 Nov 2026 17:07:14 -0500 Subject: [PATCH] test: a concat list refuses paths whose folder name holds a line break --- .../chunkEncoder.relativePaths.test.ts | 22 ++++++++++++++++++- packages/parsers/src/ffBinaries.test.ts | 18 +++++++++++++++ .../src/services/distributed/assemble.test.ts | 20 +++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/engine/src/services/chunkEncoder.relativePaths.test.ts b/packages/engine/src/services/chunkEncoder.relativePaths.test.ts index db2d78c3c8..7c4c015c89 100644 --- a/packages/engine/src/services/chunkEncoder.relativePaths.test.ts +++ b/packages/engine/src/services/chunkEncoder.relativePaths.test.ts @@ -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(), diff --git a/packages/parsers/src/ffBinaries.test.ts b/packages/parsers/src/ffBinaries.test.ts index 9817f91787..f2ad2bf175 100644 --- a/packages/parsers/src/ffBinaries.test.ts +++ b/packages/parsers/src/ffBinaries.test.ts @@ -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"); + } + }); +}); diff --git a/packages/producer/src/services/distributed/assemble.test.ts b/packages/producer/src/services/distributed/assemble.test.ts index 40ef14d112..4277697fe1 100644 --- a/packages/producer/src/services/distributed/assemble.test.ts +++ b/packages/producer/src/services/distributed/assemble.test.ts @@ -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 () => {