av_common: fix integer overflow when adjusting timebase

Found by OSS-Fuzz.
This commit is contained in:
Kacper Michajłow 2024-05-13 17:34:09 +02:00
parent 4d32db21c5
commit 1f7c223749
1 changed files with 5 additions and 3 deletions

View File

@ -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;