[FFmpeg-devel] avcodec/vp3: Check that there will be sufficient input for the coded fragments in unpack_superblocks()

Submitted by Michael Niedermayer on May 5, 2018, 7:10 p.m.

Details

Message ID 20180505191006.12876-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer May 5, 2018, 7:10 p.m.
Fixes: Timeout
Fixes: 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080

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

Comments

wm4 May 5, 2018, 7:14 p.m.
On Sat,  5 May 2018 21:10:06 +0200
Michael Niedermayer <michael@niedermayer.cc> wrote:

> Fixes: Timeout
> Fixes: 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/vp3.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 1d83753314..fcc19a627b 100644
> --- a/libavcodec/vp3.c
> +++ b/libavcodec/vp3.c
> @@ -543,7 +543,11 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
>                                           : s->y_superblock_count);
>          int num_coded_frags = 0;
>  
> -        for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
> +        for (i = sb_start; i < sb_end; i++) {
> +            if (get_bits_left(gb) < ((s->total_num_coded_frags + num_coded_frags) >> 2)) {
> +                av_log(s->avctx, AV_LOG_ERROR, "Insufficient input data for coded fragments\n");
> +                return AVERROR_INVALIDDATA;
> +            }
>              /* iterate through all 16 fragments in a superblock */
>              for (j = 0; j < 16; j++) {
>                  /* if the fragment is in bounds, check its coding status */

The log message is pointless bloat.
Michael Niedermayer May 5, 2018, 10:42 p.m.
On Sat, May 05, 2018 at 09:14:52PM +0200, wm4 wrote:
> On Sat,  5 May 2018 21:10:06 +0200
> Michael Niedermayer <michael@niedermayer.cc> wrote:
> 
> > Fixes: Timeout
> > Fixes: 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/vp3.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> > index 1d83753314..fcc19a627b 100644
> > --- a/libavcodec/vp3.c
> > +++ b/libavcodec/vp3.c
> > @@ -543,7 +543,11 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
> >                                           : s->y_superblock_count);
> >          int num_coded_frags = 0;
> >  
> > -        for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
> > +        for (i = sb_start; i < sb_end; i++) {
> > +            if (get_bits_left(gb) < ((s->total_num_coded_frags + num_coded_frags) >> 2)) {
> > +                av_log(s->avctx, AV_LOG_ERROR, "Insufficient input data for coded fragments\n");
> > +                return AVERROR_INVALIDDATA;
> > +            }
> >              /* iterate through all 16 fragments in a superblock */
> >              for (j = 0; j < 16; j++) {
> >                  /* if the fragment is in bounds, check its coding status */
> 
> The log message is pointless bloat.

All error returns of this function print a log message.

Thanks

[...]
Paul B Mahol May 6, 2018, 9:52 a.m.
On 5/6/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Sat, May 05, 2018 at 09:14:52PM +0200, wm4 wrote:
>> On Sat,  5 May 2018 21:10:06 +0200
>> Michael Niedermayer <michael@niedermayer.cc> wrote:
>>
>> > Fixes: Timeout
>> > Fixes:
>> > 6292/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_VP3_fuzzer-4871218218926080
>> >
>> > Found-by: continuous fuzzing process
>> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> > ---
>> >  libavcodec/vp3.c | 6 +++++-
>> >  1 file changed, 5 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
>> > index 1d83753314..fcc19a627b 100644
>> > --- a/libavcodec/vp3.c
>> > +++ b/libavcodec/vp3.c
>> > @@ -543,7 +543,11 @@ static int unpack_superblocks(Vp3DecodeContext *s,
>> > GetBitContext *gb)
>> >                                           : s->y_superblock_count);
>> >          int num_coded_frags = 0;
>> >
>> > -        for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
>> > +        for (i = sb_start; i < sb_end; i++) {
>> > +            if (get_bits_left(gb) < ((s->total_num_coded_frags +
>> > num_coded_frags) >> 2)) {
>> > +                av_log(s->avctx, AV_LOG_ERROR, "Insufficient input data
>> > for coded fragments\n");
>> > +                return AVERROR_INVALIDDATA;
>> > +            }
>> >              /* iterate through all 16 fragments in a superblock */
>> >              for (j = 0; j < 16; j++) {
>> >                  /* if the fragment is in bounds, check its coding
>> > status */
>>
>> The log message is pointless bloat.
>
> All error returns of this function print a log message.

Please remove log function, it is not needed at all.

Patch hide | download patch | download mbox

diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 1d83753314..fcc19a627b 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -543,7 +543,11 @@  static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
                                          : s->y_superblock_count);
         int num_coded_frags = 0;
 
-        for (i = sb_start; i < sb_end && get_bits_left(gb) > 0; i++) {
+        for (i = sb_start; i < sb_end; i++) {
+            if (get_bits_left(gb) < ((s->total_num_coded_frags + num_coded_frags) >> 2)) {
+                av_log(s->avctx, AV_LOG_ERROR, "Insufficient input data for coded fragments\n");
+                return AVERROR_INVALIDDATA;
+            }
             /* iterate through all 16 fragments in a superblock */
             for (j = 0; j < 16; j++) {
                 /* if the fragment is in bounds, check its coding status */