diff mbox series

[FFmpeg-devel,2/3] avcodec/smacker: Check remaining bits in SMK_BLK_FULL

Message ID 20201002125915.17281-2-michael@niedermayer.cc
State Accepted
Commit 42ded4d1e6fb0086a235dc584118414ae2bf30c9
Headers show
Series [FFmpeg-devel,1/3] avcodec/dxtory: Fix negative stride shift in dx2_decode_slice_420() | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer Oct. 2, 2020, 12:59 p.m. UTC
Fixes: out of array access
Fixes: 26047/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKER_fuzzer-5083031667474432

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

Comments

Andreas Rheinhardt Oct. 5, 2020, 1:24 a.m. UTC | #1
Michael Niedermayer:
> Fixes: out of array access
> Fixes: 26047/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKER_fuzzer-5083031667474432
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/smacker.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
> index 813eb862c0..6b1faec09e 100644
> --- a/libavcodec/smacker.c
> +++ b/libavcodec/smacker.c
> @@ -448,6 +448,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
>          case SMK_BLK_FULL:
>              mode = 0;
>              if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
> +                if (get_bits_left(&gb) < 1)
> +                    return AVERROR_INVALIDDATA;
>                  if(get_bits1(&gb)) mode = 1;
>                  else if(get_bits1(&gb)) mode = 2;
>              }
> 
LGTM.
(This is a file in which the type and the full tree consists of only one
entry (so that smk_get_code() never checks for overreads), isn't it? I
have to admit to have overlooked this edge case.)

- Andreas
Michael Niedermayer Oct. 17, 2020, 12:39 p.m. UTC | #2
On Mon, Oct 05, 2020 at 03:24:08AM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: out of array access
> > Fixes: 26047/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SMACKER_fuzzer-5083031667474432
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/smacker.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
> > index 813eb862c0..6b1faec09e 100644
> > --- a/libavcodec/smacker.c
> > +++ b/libavcodec/smacker.c
> > @@ -448,6 +448,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
> >          case SMK_BLK_FULL:
> >              mode = 0;
> >              if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
> > +                if (get_bits_left(&gb) < 1)
> > +                    return AVERROR_INVALIDDATA;
> >                  if(get_bits1(&gb)) mode = 1;
> >                  else if(get_bits1(&gb)) mode = 2;
> >              }
> > 
> LGTM.

will apply


> (This is a file in which the type and the full tree consists of only one
> entry (so that smk_get_code() never checks for overreads), isn't it? I
> have to admit to have overlooked this edge case.)

possibly so, id have to recheck

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c
index 813eb862c0..6b1faec09e 100644
--- a/libavcodec/smacker.c
+++ b/libavcodec/smacker.c
@@ -448,6 +448,8 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
         case SMK_BLK_FULL:
             mode = 0;
             if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
+                if (get_bits_left(&gb) < 1)
+                    return AVERROR_INVALIDDATA;
                 if(get_bits1(&gb)) mode = 1;
                 else if(get_bits1(&gb)) mode = 2;
             }