[FFmpeg-devel,2/2] avcodec/pngdec: Check nb_blocks

Submitted by Michael Niedermayer on April 28, 2019, 9:42 a.m.

Details

Message ID 20190428094251.8036-2-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer April 28, 2019, 9:42 a.m.
Fixes: Timeout (23sec -> 0.5sec)
Fixes: 14329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5679252923482112

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

Comments

Paul B Mahol April 28, 2019, 10:37 a.m.
On 4/28/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: Timeout (23sec -> 0.5sec)
> Fixes:
> 14329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5679252923482112
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/pngdec.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 6a681be29d..1dcde6cbc9 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -1541,6 +1541,8 @@ static int decode_frame_lscr(AVCodecContext *avctx,
>          return ret;
>
>      nb_blocks = bytestream2_get_le16(gb);
> +    if (2 + nb_blocks * 12 > bytestream2_get_bytes_left(gb))

I prefer if this is not reversed.

> +        return AVERROR_INVALIDDATA;
>
>      if (s->last_picture.f->data[0]) {
>          ret = av_frame_copy(frame, s->last_picture.f);
> --
> 2.21.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer May 24, 2019, 10:14 a.m.
On Sun, Apr 28, 2019 at 12:37:12PM +0200, Paul B Mahol wrote:
> On 4/28/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > Fixes: Timeout (23sec -> 0.5sec)
> > Fixes:
> > 14329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5679252923482112
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/pngdec.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> > index 6a681be29d..1dcde6cbc9 100644
> > --- a/libavcodec/pngdec.c
> > +++ b/libavcodec/pngdec.c
> > @@ -1541,6 +1541,8 @@ static int decode_frame_lscr(AVCodecContext *avctx,
> >          return ret;
> >
> >      nb_blocks = bytestream2_get_le16(gb);
> > +    if (2 + nb_blocks * 12 > bytestream2_get_bytes_left(gb))
> 
> I prefer if this is not reversed.

of course, will unreverse and push as "if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * 12)"

thanks

[...]
Paul B Mahol May 24, 2019, 10:15 a.m.
On 5/24/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Sun, Apr 28, 2019 at 12:37:12PM +0200, Paul B Mahol wrote:
>> On 4/28/19, Michael Niedermayer <michael@niedermayer.cc> wrote:
>> > Fixes: Timeout (23sec -> 0.5sec)
>> > Fixes:
>> > 14329/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5679252923482112
>> >
>> > Found-by: continuous fuzzing process
>> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> > ---
>> >  libavcodec/pngdec.c | 2 ++
>> >  1 file changed, 2 insertions(+)
>> >
>> > diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
>> > index 6a681be29d..1dcde6cbc9 100644
>> > --- a/libavcodec/pngdec.c
>> > +++ b/libavcodec/pngdec.c
>> > @@ -1541,6 +1541,8 @@ static int decode_frame_lscr(AVCodecContext
>> > *avctx,
>> >          return ret;
>> >
>> >      nb_blocks = bytestream2_get_le16(gb);
>> > +    if (2 + nb_blocks * 12 > bytestream2_get_bytes_left(gb))
>>
>> I prefer if this is not reversed.
>
> of course, will unreverse and push as "if (bytestream2_get_bytes_left(gb) <
> 2 + nb_blocks * 12)"
>
> thanks


OK.

Patch hide | download patch | download mbox

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 6a681be29d..1dcde6cbc9 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1541,6 +1541,8 @@  static int decode_frame_lscr(AVCodecContext *avctx,
         return ret;
 
     nb_blocks = bytestream2_get_le16(gb);
+    if (2 + nb_blocks * 12 > bytestream2_get_bytes_left(gb))
+        return AVERROR_INVALIDDATA;
 
     if (s->last_picture.f->data[0]) {
         ret = av_frame_copy(frame, s->last_picture.f);