diff mbox series

[FFmpeg-devel,1/7] avformat/asfdec_o: shrink extradata to the initialized size

Message ID 20210423175056.24019-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/7] avformat/asfdec_o: shrink extradata to the initialized size
Related show

Checks

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

Commit Message

Michael Niedermayer April 23, 2021, 5:50 p.m. UTC
Fixes: OOM
Fixes: 27240/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_O_fuzzer-5937469859823616

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

Comments

James Almer April 23, 2021, 6:08 p.m. UTC | #1
On 4/23/2021 2:50 PM, Michael Niedermayer wrote:
> Fixes: OOM
> Fixes: 27240/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_O_fuzzer-5937469859823616
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   libavformat/asfdec_o.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
> index 6cfcd8b088..d08a09c14d 100644
> --- a/libavformat/asfdec_o.c
> +++ b/libavformat/asfdec_o.c
> @@ -600,8 +600,12 @@ static int parse_video_info(AVIOContext *pb, AVStream *st)
>           memset(st->codecpar->extradata + st->codecpar->extradata_size , 0,
>                  AV_INPUT_BUFFER_PADDING_SIZE);
>           if ((ret = avio_read(pb, st->codecpar->extradata,
> -                             st->codecpar->extradata_size)) < 0)
> +                             st->codecpar->extradata_size)) < 0) {
> +            st->codecpar->extradata_size = 0;
> +            av_freep(&st->codecpar->extradata);
>               return ret;
> +        }
> +        st->codecpar->extradata_size = ret;

Use ff_get_extradata() instead. It will simplify the code considerably 
and get the same result.

>       }
>       return 0;
>   }
>
Michael Niedermayer April 24, 2021, 8:47 a.m. UTC | #2
On Fri, Apr 23, 2021 at 08:00:16PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: OOM
> > Fixes: 27240/clusterfuzz-testcase-minimized-ffmpeg_dem_ASF_O_fuzzer-5937469859823616
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavformat/asfdec_o.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
> > index 6cfcd8b088..d08a09c14d 100644
> > --- a/libavformat/asfdec_o.c
> > +++ b/libavformat/asfdec_o.c
> > @@ -600,8 +600,12 @@ static int parse_video_info(AVIOContext *pb, AVStream *st)
> >          memset(st->codecpar->extradata + st->codecpar->extradata_size , 0,
> >                 AV_INPUT_BUFFER_PADDING_SIZE);
> >          if ((ret = avio_read(pb, st->codecpar->extradata,
> > -                             st->codecpar->extradata_size)) < 0)
> > +                             st->codecpar->extradata_size)) < 0) {
> > +            st->codecpar->extradata_size = 0;
> > +            av_freep(&st->codecpar->extradata);
> >              return ret;
> > +        }
> > +        st->codecpar->extradata_size = ret;
> >      }
> >      return 0;
> >  }
> > 
> How important is it to preserve partially read extradata? If it is not
> important, one could just use ff_get_extradata(); if it is important,
> then memset should be performed after the read, so that the real padding
> of the extradata is zeroed (it is uninitialized with your patch if the
> desired size could not be read).

i guess its not important to preserve, will apply with ff_get_extradata()

thanks

[...]
diff mbox series

Patch

diff --git a/libavformat/asfdec_o.c b/libavformat/asfdec_o.c
index 6cfcd8b088..d08a09c14d 100644
--- a/libavformat/asfdec_o.c
+++ b/libavformat/asfdec_o.c
@@ -600,8 +600,12 @@  static int parse_video_info(AVIOContext *pb, AVStream *st)
         memset(st->codecpar->extradata + st->codecpar->extradata_size , 0,
                AV_INPUT_BUFFER_PADDING_SIZE);
         if ((ret = avio_read(pb, st->codecpar->extradata,
-                             st->codecpar->extradata_size)) < 0)
+                             st->codecpar->extradata_size)) < 0) {
+            st->codecpar->extradata_size = 0;
+            av_freep(&st->codecpar->extradata);
             return ret;
+        }
+        st->codecpar->extradata_size = ret;
     }
     return 0;
 }