Hi, If we try to extract audio from an .mp3 file starting from a point that is beyond its total duration with command: *./ffmpeg -ss 600 -i eye.mp3 -c:a libopus output.opus*
We should hit this if statement in libavformat/seek.c: if (min_ts > ts || max_ts < ts) return -1; But if the file's metadata are corrupted then min_ts and max_ts will not be the correct ones. min_ts and max_ts take the values of the metadata durations of the file. By adding the following check, we make sure that we return an error even if the metadata is corrupted: if (ts > s->duration) { av_log(NULL, AV_LOG_ERROR, "Seek position (%d) is larger than file duration (%d). Exiting...\n", ts, s->duration); return AVERROR_INVALIDDATA; } This is my first patch submission. Please let me know if any modifications are needed. Thanks, bayesiandog
From f586e036abd8a744ef8b650071e22d873e0cdacc Mon Sep 17 00:00:00 2001 From: bayesiandog <memoryvesti...@gmail.com> Date: Sat, 1 Mar 2025 15:45:42 +0200 Subject: [PATCH] Fix seeking beyond file duration by returning an error when metadata is incorrect --- libavformat/seek.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/seek.c b/libavformat/seek.c index 9518f0f41c..90b374b332 100644 --- a/libavformat/seek.c +++ b/libavformat/seek.c @@ -668,8 +668,8 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int ret; if (ts > s->duration) { - av_log(NULL, AV_LOG_ERROR, "Seek position (%d) is larger than file duration (%d). Exiting...\n", ts, s->duration); - exit(1); + av_log(NULL, AV_LOG_ERROR, "Seek position (%lld) is larger than file duration (%lld). Check metadata...\n", ts, s->duration); + return AVERROR_INVALIDDATA; } if (min_ts > ts || max_ts < ts) -- 2.39.5
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".