lavf: avoid integer overflow when estimating bitrate

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
(cherry picked from commit df33a58e53)
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
Anton Khirnov
2013-08-24 21:30:46 +02:00
committed by Luca Barbato
parent 1e9d234c0c
commit 4cb3efc206

View File

@@ -1863,8 +1863,13 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
bit_rate = 0;
for(i=0;i<ic->nb_streams;i++) {
st = ic->streams[i];
if (st->codec->bit_rate > 0)
bit_rate += st->codec->bit_rate;
if (st->codec->bit_rate > 0) {
if (INT_MAX - st->codec->bit_rate > bit_rate) {
bit_rate = 0;
break;
}
bit_rate += st->codec->bit_rate;
}
}
ic->bit_rate = bit_rate;
}