[FFmpeg-cvslog] lavc/aac_ac3_parser: fix potential overflow when averaging bitrate

Alexander Strasser git at videolan.org
Wed Aug 12 18:38:47 EEST 2020


ffmpeg | branch: master | Alexander Strasser <eclipse7 at gmx.net> | Fri Jul 17 20:51:43 2020 +0200| [ecd71916d1e573a4b91b1fd182f3d232a1693dff] | committer: Alexander Strasser

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 <barryjzhao at tencent.com>
Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>

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

 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



More information about the ffmpeg-cvslog mailing list