diff mbox series

[FFmpeg-devel,4/7] avformat/icodec: Check for zero streams and stream creation failure

Message ID 20201104000649.14740-4-michael@niedermayer.cc
State Accepted
Commit b33233bd53f74f94f4cd7be0645a99a9549a913e
Headers show
Series [FFmpeg-devel,1/7] avformat/mpc8: correct 32bit timestamp truncation | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Michael Niedermayer Nov. 4, 2020, 12:06 a.m. UTC
Fixes: NULL pointer dereference
Fixes: 26814/clusterfuzz-testcase-minimized-ffmpeg_dem_ICO_fuzzer-5758487797432320

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/icodec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Peter Ross Nov. 13, 2020, 6:37 a.m. UTC | #1
On Wed, Nov 04, 2020 at 01:06:46AM +0100, Michael Niedermayer wrote:
> Fixes: NULL pointer dereference
> Fixes: 26814/clusterfuzz-testcase-minimized-ffmpeg_dem_ICO_fuzzer-5758487797432320
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/icodec.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/icodec.c b/libavformat/icodec.c
> index cf1e60815e..93179bb41e 100644
> --- a/libavformat/icodec.c
> +++ b/libavformat/icodec.c
> @@ -84,6 +84,9 @@ static int read_header(AVFormatContext *s)
>      avio_skip(pb, 4);
>      ico->nb_images = avio_rl16(pb);
>  
> +    if (!ico->nb_images)
> +        return AVERROR_INVALIDDATA;
> +
>      ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage));
>      if (!ico->images)
>          return AVERROR(ENOMEM);
> @@ -93,7 +96,7 @@ static int read_header(AVFormatContext *s)
>          int tmp;
>  
>          if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
> -            break;
> +            goto fail;
>  
>          st = avformat_new_stream(s, NULL);
>          if (!st) {
> @@ -118,7 +121,7 @@ static int read_header(AVFormatContext *s)
>          ico->images[i].offset = avio_rl32(pb);
>  
>          if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
> -            break;
> +            goto fail;
>  
>          codec = avio_rl32(pb);
>          switch (codec) {
> -- 
> 2.17.1

looks good

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
Michael Niedermayer Nov. 13, 2020, 5:03 p.m. UTC | #2
On Fri, Nov 13, 2020 at 05:37:39PM +1100, Peter Ross wrote:
> On Wed, Nov 04, 2020 at 01:06:46AM +0100, Michael Niedermayer wrote:
> > Fixes: NULL pointer dereference
> > Fixes: 26814/clusterfuzz-testcase-minimized-ffmpeg_dem_ICO_fuzzer-5758487797432320
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/icodec.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavformat/icodec.c b/libavformat/icodec.c
> > index cf1e60815e..93179bb41e 100644
> > --- a/libavformat/icodec.c
> > +++ b/libavformat/icodec.c
> > @@ -84,6 +84,9 @@ static int read_header(AVFormatContext *s)
> >      avio_skip(pb, 4);
> >      ico->nb_images = avio_rl16(pb);
> >  
> > +    if (!ico->nb_images)
> > +        return AVERROR_INVALIDDATA;
> > +
> >      ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage));
> >      if (!ico->images)
> >          return AVERROR(ENOMEM);
> > @@ -93,7 +96,7 @@ static int read_header(AVFormatContext *s)
> >          int tmp;
> >  
> >          if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
> > -            break;
> > +            goto fail;
> >  
> >          st = avformat_new_stream(s, NULL);
> >          if (!st) {
> > @@ -118,7 +121,7 @@ static int read_header(AVFormatContext *s)
> >          ico->images[i].offset = avio_rl32(pb);
> >  
> >          if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
> > -            break;
> > +            goto fail;
> >  
> >          codec = avio_rl32(pb);
> >          switch (codec) {
> > -- 
> > 2.17.1
> 
> looks good

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/icodec.c b/libavformat/icodec.c
index cf1e60815e..93179bb41e 100644
--- a/libavformat/icodec.c
+++ b/libavformat/icodec.c
@@ -84,6 +84,9 @@  static int read_header(AVFormatContext *s)
     avio_skip(pb, 4);
     ico->nb_images = avio_rl16(pb);
 
+    if (!ico->nb_images)
+        return AVERROR_INVALIDDATA;
+
     ico->images = av_malloc_array(ico->nb_images, sizeof(IcoImage));
     if (!ico->images)
         return AVERROR(ENOMEM);
@@ -93,7 +96,7 @@  static int read_header(AVFormatContext *s)
         int tmp;
 
         if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0)
-            break;
+            goto fail;
 
         st = avformat_new_stream(s, NULL);
         if (!st) {
@@ -118,7 +121,7 @@  static int read_header(AVFormatContext *s)
         ico->images[i].offset = avio_rl32(pb);
 
         if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0)
-            break;
+            goto fail;
 
         codec = avio_rl32(pb);
         switch (codec) {