Skip to content

Commit

Permalink
lavc/aac_ac3_parser: fix potential overflow when averaging bitrate
Browse files Browse the repository at this point in the history
The new code is analog to how it's done in our mpegaudio parser.

Acked-by: Jun Zhao <[email protected]>
Signed-off-by: Alexander Strasser <[email protected]>
  • Loading branch information
beastd committed Aug 12, 2020
1 parent 1201687 commit ecd7191
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions libavcodec/aac_ac3_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ int ff_aac_ac3_parse(AVCodecParserContext *s1,
/* 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;
}
}

Expand Down
1 change: 0 additions & 1 deletion libavcodec/aac_ac3_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ typedef struct AACAC3ParseContext {

int need_next_header;
int frame_number;
int last_bit_rate;
enum AVCodecID codec_id;
} AACAC3ParseContext;

Expand Down
2 changes: 1 addition & 1 deletion tests/ref/fate/adtstoasc_ticket3715
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ecd7191

Please sign in to comment.