[FFmpeg-cvslog] avcodec/utils: Check bitrate for overflow in get_bit_rate()

Michael Niedermayer git at videolan.org
Sat Dec 19 21:23:31 EET 2020


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sun Oct 25 19:19:54 2020 +0100| [8aadae670f28b88e94770262cd1136562bdb2f45] | committer: Michael Niedermayer

avcodec/utils: Check bitrate for overflow in get_bit_rate()

Fixes: signed integer overflow: 617890810133996544 * 16 cannot be represented in type 'long'
Fixes: 26565/clusterfuzz-testcase-minimized-ffmpeg_dem_MV_fuzzer-5092054700654592

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8aadae670f28b88e94770262cd1136562bdb2f45
---

 libavcodec/utils.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 0226e36ee7..b2313860d0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -513,7 +513,14 @@ static int64_t get_bit_rate(AVCodecContext *ctx)
         break;
     case AVMEDIA_TYPE_AUDIO:
         bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
-        bit_rate = bits_per_sample ? ctx->sample_rate * (int64_t)ctx->channels * bits_per_sample : ctx->bit_rate;
+        if (bits_per_sample) {
+            bit_rate = ctx->sample_rate * (int64_t)ctx->channels;
+            if (bit_rate > INT64_MAX / bits_per_sample) {
+                bit_rate = 0;
+            } else
+                bit_rate *= bits_per_sample;
+        } else
+            bit_rate = ctx->bit_rate;
         break;
     default:
         bit_rate = 0;



More information about the ffmpeg-cvslog mailing list