From ecd71916d1e573a4b91b1fd182f3d232a1693dff Mon Sep 17 00:00:00 2001 From: Alexander Strasser Date: Fri, 17 Jul 2020 20:51:43 +0200 Subject: [PATCH] lavc/aac_ac3_parser: fix potential overflow when averaging bitrate The new code is analog to how it's done in our mpegaudio parser. Acked-by: Jun Zhao Signed-off-by: Alexander Strasser --- libavcodec/aac_ac3_parser.c | 5 ++--- libavcodec/aac_ac3_parser.h | 1 - tests/ref/fate/adtstoasc_ticket3715 | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/aac_ac3_parser.c b/libavcodec/aac_ac3_parser.c index 0746798dab..e5d4b53339 100644 --- a/libavcodec/aac_ac3_parser.c +++ b/libavcodec/aac_ac3_parser.c @@ -100,9 +100,8 @@ get_next: /* Calculate the average bit rate */ s->frame_number++; if (avctx->codec_id != AV_CODEC_ID_EAC3) { - avctx->bit_rate = - (s->last_bit_rate * (s->frame_number -1) + s->bit_rate)/s->frame_number; - s->last_bit_rate = avctx->bit_rate; + avctx->bit_rate += + (s->bit_rate - avctx->bit_rate) / s->frame_number; } } diff --git a/libavcodec/aac_ac3_parser.h b/libavcodec/aac_ac3_parser.h index b04041f69d..8b93cbf84f 100644 --- a/libavcodec/aac_ac3_parser.h +++ b/libavcodec/aac_ac3_parser.h @@ -56,7 +56,6 @@ typedef struct AACAC3ParseContext { int need_next_header; int frame_number; - int last_bit_rate; enum AVCodecID codec_id; } AACAC3ParseContext; diff --git a/tests/ref/fate/adtstoasc_ticket3715 b/tests/ref/fate/adtstoasc_ticket3715 index 3b473ee99e..fbdeeb0582 100644 --- a/tests/ref/fate/adtstoasc_ticket3715 +++ b/tests/ref/fate/adtstoasc_ticket3715 @@ -1,4 +1,4 @@ -3e63cbb6bb6ec756d79fab2632fef305 *tests/data/fate/adtstoasc_ticket3715.mov +29ef0632a8eb5c336bf45a1d5076626e *tests/data/fate/adtstoasc_ticket3715.mov 33324 tests/data/fate/adtstoasc_ticket3715.mov #extradata 0: 2, 0x00340022 #tb 0: 1/44100