diff options
author | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2021-10-20 14:52:06 +0100 |
---|---|---|
committer | Derek Buitenhuis <derek.buitenhuis@gmail.com> | 2021-10-21 14:34:36 +0100 |
commit | a987b5c9ee282de4a4ed2aaf8f2640ed09f705e9 (patch) | |
tree | a829036bfe1bced455ea444f4f351837dcb7c658 /libavformat | |
parent | f24028c798397af720acb838357785aa705a8122 (diff) | |
download | ffmpeg-a987b5c9ee282de4a4ed2aaf8f2640ed09f705e9.tar.gz |
avformat/mov: Use av_rescale when calculating bit rate
It is less susceptible to overflows.
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/mov.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c index 57c67e3aac..841818b547 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7989,12 +7989,14 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (st->duration > 0) { - if (sc->data_size > INT64_MAX / sc->time_scale / 8) { + /* Akin to sc->data_size * 8 * sc->time_scale / st->duration but accounting for overflows. */ + st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) sc->time_scale) * 8, st->duration); + if (st->codecpar->bit_rate == INT64_MIN) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); + st->codecpar->bit_rate = 0; return AVERROR_INVALIDDATA; } - st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; } } } @@ -8004,13 +8006,14 @@ static int mov_read_header(AVFormatContext *s) AVStream *st = s->streams[i]; MOVStreamContext *sc = st->priv_data; if (sc->duration_for_fps > 0) { - if (sc->data_size > INT64_MAX / sc->time_scale / 8) { + /* Akin to sc->data_size * 8 * sc->time_scale / sc->duration_for_fps but accounting for overflows. */ + st->codecpar->bit_rate = av_rescale(sc->data_size, ((int64_t) sc->time_scale) * 8, sc->duration_for_fps); + if (st->codecpar->bit_rate == INT64_MIN) { av_log(s, AV_LOG_ERROR, "Overflow during bit rate calculation %"PRId64" * 8 * %d\n", sc->data_size, sc->time_scale); + st->codecpar->bit_rate = 0; return AVERROR_INVALIDDATA; } - st->codecpar->bit_rate = sc->data_size * 8 * sc->time_scale / - sc->duration_for_fps; } } } |