[10/11] rl2: Avoid a division by zero

Message ID 1379599756-27062-10-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö Sept. 19, 2013, 2:09 p.m.
Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
---
 libavformat/rl2.c |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Luca Barbato Sept. 19, 2013, 2:24 p.m. | #1
On 19/09/13 16:09, Martin Storsjö wrote:
> Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
> CC: libav-stable@libav.org
> ---
>  libavformat/rl2.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 

Ok, I guess.

lu
Kostya Shishkov Sept. 19, 2013, 2:25 p.m. | #2
On Thu, Sep 19, 2013 at 05:09:15PM +0300, Martin Storsjö wrote:
> Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
> CC: libav-stable@libav.org
> ---
>  libavformat/rl2.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/rl2.c b/libavformat/rl2.c
> index ac0532f..9effcef 100644
> --- a/libavformat/rl2.c
> +++ b/libavformat/rl2.c
> @@ -107,6 +107,10 @@ static av_cold int rl2_read_header(AVFormatContext *s)
>      rate = avio_rl16(pb);
>      channels = avio_rl16(pb);
>      def_sound_size = avio_rl16(pb);
> +    if (!channels) {
> +        av_log(s, AV_LOG_ERROR, "Invalid number of channels\n");
> +        return AVERROR_INVALIDDATA;
> +    }
>  
>      /** setup video stream */
>      st = avformat_new_stream(s, NULL);
> -- 

I'd also error out on >42 channels but that's just me
the patch should be OK though

Patch

diff --git a/libavformat/rl2.c b/libavformat/rl2.c
index ac0532f..9effcef 100644
--- a/libavformat/rl2.c
+++ b/libavformat/rl2.c
@@ -107,6 +107,10 @@  static av_cold int rl2_read_header(AVFormatContext *s)
     rate = avio_rl16(pb);
     channels = avio_rl16(pb);
     def_sound_size = avio_rl16(pb);
+    if (!channels) {
+        av_log(s, AV_LOG_ERROR, "Invalid number of channels\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     /** setup video stream */
     st = avformat_new_stream(s, NULL);