mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
test: a concat list refuses paths whose folder name holds a line break
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user