diff mbox series

[FFmpeg-devel,2/2] avcodec/h263dec: Avoid parsing extradata repeatedly

Message ID 20221117231418.20994-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec/tiff: Avoid 0.0/0.0 in camera_xyz_coeff() | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer Nov. 17, 2022, 11:14 p.m. UTC
Fixes: Timeout
Fixes: 52329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4716563886637056

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/h263dec.c   | 3 ++-
 libavcodec/mpegvideo.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Anton Khirnov Nov. 21, 2022, 11:53 a.m. UTC | #1
Quoting Michael Niedermayer (2022-11-18 00:14:18)
> Fixes: Timeout
> Fixes: 52329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4716563886637056
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/h263dec.c   | 3 ++-
>  libavcodec/mpegvideo.h | 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> index 71b846ba74..4eab43d939 100644
> --- a/libavcodec/h263dec.c
> +++ b/libavcodec/h263dec.c
> @@ -492,11 +492,12 @@ retry:
>      } else if (CONFIG_MSMPEG4DEC && s->msmpeg4_version) {
>          ret = ff_msmpeg4_decode_picture_header(s);
>      } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
> -        if (s->avctx->extradata_size && s->picture_number == 0) {
> +        if (s->avctx->extradata_size && s->picture_number == 0 && !s->extradata_parsed) {

Wouldn't it make sense to get rid of the picture_number condition now?
Michael Niedermayer Nov. 21, 2022, 6:53 p.m. UTC | #2
On Mon, Nov 21, 2022 at 12:53:26PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2022-11-18 00:14:18)
> > Fixes: Timeout
> > Fixes: 52329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4716563886637056
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/h263dec.c   | 3 ++-
> >  libavcodec/mpegvideo.h | 1 +
> >  2 files changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> > index 71b846ba74..4eab43d939 100644
> > --- a/libavcodec/h263dec.c
> > +++ b/libavcodec/h263dec.c
> > @@ -492,11 +492,12 @@ retry:
> >      } else if (CONFIG_MSMPEG4DEC && s->msmpeg4_version) {
> >          ret = ff_msmpeg4_decode_picture_header(s);
> >      } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
> > -        if (s->avctx->extradata_size && s->picture_number == 0) {
> > +        if (s->avctx->extradata_size && s->picture_number == 0 && !s->extradata_parsed) {
> 
> Wouldn't it make sense to get rid of the picture_number condition now?

I was thinking about droping it too. I dont know why i didnt, you are correct

thx

[...]
Michael Niedermayer Nov. 28, 2022, 7:50 p.m. UTC | #3
On Mon, Nov 21, 2022 at 07:53:53PM +0100, Michael Niedermayer wrote:
> On Mon, Nov 21, 2022 at 12:53:26PM +0100, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2022-11-18 00:14:18)
> > > Fixes: Timeout
> > > Fixes: 52329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MPEG4_fuzzer-4716563886637056
> > > 
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/h263dec.c   | 3 ++-
> > >  libavcodec/mpegvideo.h | 1 +
> > >  2 files changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> > > index 71b846ba74..4eab43d939 100644
> > > --- a/libavcodec/h263dec.c
> > > +++ b/libavcodec/h263dec.c
> > > @@ -492,11 +492,12 @@ retry:
> > >      } else if (CONFIG_MSMPEG4DEC && s->msmpeg4_version) {
> > >          ret = ff_msmpeg4_decode_picture_header(s);
> > >      } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
> > > -        if (s->avctx->extradata_size && s->picture_number == 0) {
> > > +        if (s->avctx->extradata_size && s->picture_number == 0 && !s->extradata_parsed) {
> > 
> > Wouldn't it make sense to get rid of the picture_number condition now?
> 
> I was thinking about droping it too. I dont know why i didnt, you are correct

will apply with the picture_number condition removed

[...]
diff mbox series

Patch

diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 71b846ba74..4eab43d939 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -492,11 +492,12 @@  retry:
     } else if (CONFIG_MSMPEG4DEC && s->msmpeg4_version) {
         ret = ff_msmpeg4_decode_picture_header(s);
     } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
-        if (s->avctx->extradata_size && s->picture_number == 0) {
+        if (s->avctx->extradata_size && s->picture_number == 0 && !s->extradata_parsed) {
             GetBitContext gb;
 
             if (init_get_bits8(&gb, s->avctx->extradata, s->avctx->extradata_size) >= 0 )
                 ff_mpeg4_decode_picture_header(avctx->priv_data, &gb, 1, 0);
+            s->extradata_parsed = 1;
         }
         ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0);
     } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index ccec0dd75f..6440b906b1 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -117,6 +117,7 @@  typedef struct MpegEncContext {
     int input_picture_number;  ///< used to set pic->display_picture_number, should not be used for/by anything else
     int coded_picture_number;  ///< used to set pic->coded_picture_number, should not be used for/by anything else
     int picture_number;       //FIXME remove, unclear definition
+    int extradata_parsed;
     int picture_in_gop_number; ///< 0-> first pic in gop, ...
     int mb_width, mb_height;   ///< number of MBs horizontally & vertically
     int mb_stride;             ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11