wmadec: Check the number of channels before initing

Message ID 1341069326-18340-1-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö June 30, 2012, 3:15 p.m.
From: Michael Niedermayer <michaelni@gmx.at>

This fixes crashes with invalid files.

Based on patch by Piotr Bandurski.
---
 libavcodec/wmadec.c |    5 +++++
 1 file changed, 5 insertions(+)

Comments

Luca Barbato June 30, 2012, 4:01 p.m. | #1
On 06/30/2012 05:15 PM, Martin Storsjö wrote:
> From: Michael Niedermayer <michaelni@gmx.at>
> 
> This fixes crashes with invalid files.
> 
> Based on patch by Piotr Bandurski.
> ---
>  libavcodec/wmadec.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
> index a730059..4fdfe74 100644
> --- a/libavcodec/wmadec.c
> +++ b/libavcodec/wmadec.c
> @@ -102,6 +102,11 @@ static int wma_decode_init(AVCodecContext * avctx)
>      s->use_bit_reservoir = flags2 & 0x0002;
>      s->use_variable_block_len = flags2 & 0x0004;
>  
> +    if (avctx->channels > MAX_CHANNELS) {
> +        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels (%d)\n", avctx->channels);
> +        return AVERROR(EINVAL);
> +    }
> +
>      if(ff_wma_init(avctx, flags2)<0)


wma_init has similar checks in place, might be better move it here?

lu

Patch

diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c
index a730059..4fdfe74 100644
--- a/libavcodec/wmadec.c
+++ b/libavcodec/wmadec.c
@@ -102,6 +102,11 @@  static int wma_decode_init(AVCodecContext * avctx)
     s->use_bit_reservoir = flags2 & 0x0002;
     s->use_variable_block_len = flags2 & 0x0004;
 
+    if (avctx->channels > MAX_CHANNELS) {
+        av_log(avctx, AV_LOG_ERROR, "Invalid number of channels (%d)\n", avctx->channels);
+        return AVERROR(EINVAL);
+    }
+
     if(ff_wma_init(avctx, flags2)<0)
         return -1;