Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] #7107 [PATCH] Fix seeking beyond file duration by returning an error when metadata is incorrect
@ 2025-03-01 13:51 Haris
  0 siblings, 0 replies; only message in thread
From: Haris @ 2025-03-01 13:51 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 824 bytes --]

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

[-- Attachment #2: 0001-Fix-seeking-beyond-file-duration-by-returning-an-err.patch --]
[-- Type: text/x-patch, Size: 994 bytes --]

From f586e036abd8a744ef8b650071e22d873e0cdacc Mon Sep 17 00:00:00 2001
From: bayesiandog <memoryvestiges@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


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-01 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-01 13:51 [FFmpeg-devel] #7107 [PATCH] Fix seeking beyond file duration by returning an error when metadata is incorrect Haris

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git