summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2024-05-13 17:34:09 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-05-15 01:25:18 +0200
commit1f7c223749b71d4e4976d0b294b37d766655ea95 (patch)
treeea5d62834df214dda3a21e9152b2f0c0c414b649 /common
parent4d32db21c50db8cd9f2e7925c4b37f1490d85963 (diff)
downloadmpv-1f7c223749b71d4e4976d0b294b37d766655ea95.tar.bz2
mpv-1f7c223749b71d4e4976d0b294b37d766655ea95.tar.xz
av_common: fix integer overflow when adjusting timebase
Found by OSS-Fuzz.
Diffstat (limited to 'common')
-rw-r--r--common/av_common.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/common/av_common.c b/common/av_common.c
index 277601d2fc..1a23d766b3 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -143,12 +143,14 @@ AVRational mp_get_codec_timebase(const struct mp_codec_params *c)
// If the timebase is too coarse, raise its precision, or small adjustments
// to timestamps done between decoder and demuxer could be lost.
+ int64_t den = tb.den;
if (av_q2d(tb) > 0.001) {
- AVRational r = av_div_q(tb, (AVRational){1, 1000});
- tb.den *= (r.num + r.den - 1) / r.den;
+ int64_t scaling_num = tb.num * INT64_C(1000);
+ int64_t scaling_den = tb.den;
+ den *= (scaling_num + scaling_den - 1) / scaling_den;
}
- av_reduce(&tb.num, &tb.den, tb.num, tb.den, INT_MAX);
+ av_reduce(&tb.num, &tb.den, tb.num, den, INT_MAX);
if (tb.num < 1 || tb.den < 1)
tb = AV_TIME_BASE_Q;