fix(audio): refuse trim windows shorter than one codec frame (#679)

trim-audio stream-copies, and a window below one frame ships a container with zero audio frames as a 200 success. Floor the window at 0.1s in the schema, and refuse after endS clamps to the real duration if the window drops under the floor. Fixes #671.
This commit is contained in:
SnapOtter
2026-07-30 09:34:56 +08:00
committed by GitHub
parent 6aacb4f3a9
commit 192d56e2ca
3 changed files with 34 additions and 1 deletions
@@ -67,4 +67,17 @@ describe.skipIf(!ffmpegAvailable())("trim-audio (requires ffmpeg)", () => {
const res = await runTool({ startS: 0.5, endS: 0.2 });
expect(res.statusCode).toBe(400);
});
it("rejects a sub-frame trim window instead of returning an empty file", async () => {
const res = await runTool({ startS: 0, endS: 0.000001 });
expect(res.statusCode).toBe(400);
});
it("rejects when clamping endS to the duration leaves a sub-frame window", async () => {
// tiny.mp3 is ~1.0-1.045s depending on the ffprobe build; endS clamps to
// the duration, leaving well under 0.1s either way.
const res = await runTool({ startS: 0.98, endS: 9 });
expect(res.statusCode).toBe(422);
expect(JSON.parse(res.body).details).toMatch(/Trim window/);
});
});
@@ -41,6 +41,14 @@ describe("media time settings schemas", () => {
expect(parses("trim-video", { startS: 0, endS: Number.MIN_VALUE })).toBe(false);
});
it("rejects trim-audio windows shorter than the stream-copy floor", () => {
// Stream copy cannot cut below one codec frame (mp3 ~26ms, flac up to
// ~93ms), so windows under 0.1s ship a file with zero audio frames.
expect(parses("trim-audio", { startS: 0, endS: 0.000001 })).toBe(false);
expect(parses("trim-audio", { startS: 5, endS: 5.05 })).toBe(false);
expect(parses("trim-audio", { startS: 0, endS: 0.5 })).toBe(true);
});
it("requires at least one representable fade duration", () => {
expect(parses("fade-audio", { fadeInS: Number.MIN_VALUE, fadeOutS: 0 })).toBe(false);
expect(parses("fade-audio", { fadeInS: 0, fadeOutS: 0.000001 })).toBe(true);