twinvqdec: Check the ibps parameter separately

Message ID 1379435764-12356-1-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Sept. 17, 2013, 4:36 p.m.
This is required, since invalid parameters actually could
pass the switch check below.

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
---
 libavcodec/twinvqdec.c |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Kostya Shishkov Sept. 17, 2013, 4:45 p.m. | #1
On Tue, Sep 17, 2013 at 07:36:04PM +0300, Martin Storsjö wrote:
> This is required, since invalid parameters actually could
> pass the switch check below.
> 
> Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
> CC: libav-stable@libav.org
> ---
>  libavcodec/twinvqdec.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
> index a88b6ff..5279fe5 100644
> --- a/libavcodec/twinvqdec.c
> +++ b/libavcodec/twinvqdec.c
> @@ -356,6 +356,10 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx)
>                                                   : AV_CH_LAYOUT_STEREO;
>  
>      ibps = avctx->bit_rate / (1000 * avctx->channels);
> +    if (ibps < 8 || ibps > 48) {
> +        av_log(avctx, AV_LOG_ERROR, "Bad bitrate/channels combination\n");
> +        return AVERROR_INVALIDDATA;
> +    }
>  
>      switch ((isampf << 8) + ibps) {
>      case (8 << 8) + 8:
> -- 

bikeshed: bad bitrate per channel value %d kbps

LGTM

Patch

diff --git a/libavcodec/twinvqdec.c b/libavcodec/twinvqdec.c
index a88b6ff..5279fe5 100644
--- a/libavcodec/twinvqdec.c
+++ b/libavcodec/twinvqdec.c
@@ -356,6 +356,10 @@  static av_cold int twinvq_decode_init(AVCodecContext *avctx)
                                                  : AV_CH_LAYOUT_STEREO;
 
     ibps = avctx->bit_rate / (1000 * avctx->channels);
+    if (ibps < 8 || ibps > 48) {
+        av_log(avctx, AV_LOG_ERROR, "Bad bitrate/channels combination\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     switch ((isampf << 8) + ibps) {
     case (8 << 8) + 8: