[FFmpeg-devel] #7107 [PATCH] Fix seeking beyond file duration by returning an error when metadata is incorrect

Haris memoryvestiges at gmail.com
Sat Mar 1 15:51:52 EET 2025


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-seeking-beyond-file-duration-by-returning-an-err.patch
Type: text/x-patch
Size: 994 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250301/14ce604a/attachment.bin>


More information about the ffmpeg-devel mailing list