PR #23832 opened by John_Smith_LYI URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23832 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23832.patch
# fftools: reject negative -t durations ## Description FFmpeg documents `-t` as an input/output duration option. Input-side `-t` limits how much input data is read, output-side `-t` stops writing after the requested duration, and `-t` takes priority over `-to`. Tested on FFmpeg commit `ceabc9b306f5385d92efdd9cd18d210deb3055b3`. ## Issue Previously, negative `-t` values reached later streamcopy or trim handling. In the streamcopy output path, `-t -1` could finish with a zero exit status and only report an empty-output warning: ```sh ffmpeg -f lavfi -i testsrc2=s=32x32:r=1 -c copy -f null -t -1 - ``` The same semantic issue exists for input-side `-t`: the option resolves to a negative recording duration and should be rejected before input processing starts. ## Fix This change rejects negative resolved recording durations in both input and output open paths, before they reach the streamcopy or filter/trim logic. The existing `-t 0` behavior is preserved. The change affects only the `ffmpeg` command-line tool behavior. It does not change public API or ABI. ## Validation ```sh make -j$(nproc) fate-ffmpeg-negative-t V=1 make -j$(nproc) fate-ffmpeg-negative-t fate-ffmpeg-negative-input-t fate-ffmpeg-streamcopy-t V=1 make -j$(nproc) fate-ffmpeg-filter-in-eof fate-ffmpeg-filter_complex fate-ffmpeg-filter_complex_audio fate-ffmpeg-lavfi fate-ffmpeg-loopback-decoding fate-ffmpeg-negative-input-t fate-ffmpeg-negative-t fate-ffmpeg-streamcopy-t make -j$(nproc) TARGET_SAMPLES=/tmp/ffmpeg-fate-samples fate make fate-list-failing # output was empty git diff --check git diff | ./tools/patcheck - printf '%s\n\n%s\n' 'fftools: reject negative -t durations' 'Reject negative recording durations for input and output -t before they reach streamcopy or trim handling. Keep -t 0 accepted.' | sh ./tools/check_commit_msg.sh ``` `patcheck` reported only the standard "Missing changelog entry" hint, which is not needed for this command-line validation fix. From 58a53ead64efe5d81bfa5556d48b73dc026ae54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B0=B8=E9=B9=8F?= <[email protected]> Date: Thu, 16 Jul 2026 20:30:29 +0800 Subject: [PATCH] fftools: reject negative -t durations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reject negative recording durations for input and output -t before they reach streamcopy or trim handling. Keep -t 0 accepted. Signed-off-by: 张永鹏 <[email protected]> --- fftools/ffmpeg_demux.c | 5 +++++ fftools/ffmpeg_mux_init.c | 5 +++++ tests/fate/ffmpeg.mak | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 8a165faf1d..0d8ccf21ee 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -2289,6 +2289,11 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch) } } + if (recording_time != INT64_MAX && recording_time < 0) { + av_log(d, AV_LOG_ERROR, "-t value must be non-negative; aborting.\n"); + return AVERROR(EINVAL); + } + if (o->format) { if (!(file_iformat = av_find_input_format(o->format))) { av_log(d, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 7a238b10ff..5f4e1d1178 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -3489,6 +3489,11 @@ int of_open(const OptionsContext *o, const char *filename, Scheduler *sch) } } + if (recording_time != INT64_MAX && recording_time < 0) { + av_log(mux, AV_LOG_ERROR, "-t value must be non-negative; aborting.\n"); + return AVERROR(EINVAL); + } + of->recording_time = recording_time; of->start_time = o->start_time; diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak index db6a171898..55c9ceb6bd 100644 --- a/tests/fate/ffmpeg.mak +++ b/tests/fate/ffmpeg.mak @@ -267,6 +267,20 @@ fate-ffmpeg-streamcopy-t: CMD = ffmpeg -c copy -f null -t 1 - FATE_FFMPEG-$(call REMUX, RAWVIDEO, NULL_MUXER) += fate-ffmpeg-streamcopy-t +fate-ffmpeg-negative-t: tests/data/vsynth1.yuv +fate-ffmpeg-negative-t: CMP = null +fate-ffmpeg-negative-t: CMD = ffmpeg \ + -stream_loop -1 -f rawvideo -s 352x288 -pix_fmt yuv420p -i $(TARGET_PATH)/tests/data/vsynth1.yuv \ + -c copy -f null -t -1 -; test $$? -ne 0 +FATE_FFMPEG-$(call REMUX, RAWVIDEO, NULL_MUXER) += fate-ffmpeg-negative-t + +fate-ffmpeg-negative-input-t: tests/data/vsynth1.yuv +fate-ffmpeg-negative-input-t: CMP = null +fate-ffmpeg-negative-input-t: CMD = ffmpeg \ + -stream_loop -1 -f rawvideo -s 352x288 -pix_fmt yuv420p -t -1 -i $(TARGET_PATH)/tests/data/vsynth1.yuv \ + -c copy -f null -; test $$? -ne 0 +FATE_FFMPEG-$(call REMUX, RAWVIDEO, NULL_MUXER) += fate-ffmpeg-negative-input-t + # Test loopback decoding and passing the output to a complex graph. fate-ffmpeg-loopback-decoding: tests/data/vsynth1.yuv fate-ffmpeg-loopback-decoding: CMD = transcode \ -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
