Commit 26f4248260 for ffmpeg
commit 26f42482604cbcebd43c612d2f9011d70b51ee1b
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Wed Nov 11 17:00:22 2026 +0100
avformat/imfdec: check the coherence of a seek target without overflow
Fixes: signed integer overflow: 216000000000000 * 48000 cannot be represented in type 'int64_t' (aka 'long')
Fixes: A5TJ4YnA1yYe
Found during the triage of a finding from the review of https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25795
Signed integer overflow Replicated through UnModified FFmpeg with UBSAN
diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index e92c968865..46de8c9a9d 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -946,16 +946,8 @@ static int imf_probe(const AVProbeData *p)
static int coherent_ts(int64_t ts, AVRational in_tb, AVRational out_tb)
{
- int dst_num;
- int dst_den;
- int ret;
-
- ret = av_reduce(&dst_num, &dst_den, ts * in_tb.num * out_tb.den,
- in_tb.den * out_tb.num, INT64_MAX);
- if (!ret || dst_den != 1)
- return 0;
-
- return 1;
+ return av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_DOWN) ==
+ av_rescale_q_rnd(ts, in_tb, out_tb, AV_ROUND_UP);
}
static int imf_seek(AVFormatContext *s, int stream_index, int64_t min_ts,