[FFmpeg-devel] avcodec/pngdec: Check input space

Submitted by Michael Niedermayer on May 14, 2019, 7:38 p.m.

Details

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

Commit Message

Michael Niedermayer May 14, 2019, 7:38 p.m.
Fixes: Timeout (33sec -> 78ms)
Fixes: 14668/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5767073352908800

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 | 3 +++
 1 file changed, 3 insertions(+)

Comments

Kieran Kunhya May 14, 2019, 7:52 p.m.
On Tue, 14 May 2019 at 20:42, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> Fixes: Timeout (33sec -> 78ms)
> Fixes:
> 14668/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5767073352908800
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by
> <https://github.com/google/oss-fuzz/tree/master/projects/ffmpegSigned-off-by>:
> Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/pngdec.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> index 6a681be29d..78988d9e75 100644
> --- a/libavcodec/pngdec.c
> +++ b/libavcodec/pngdec.c
> @@ -1535,6 +1535,9 @@ static int decode_frame_lscr(AVCodecContext *avctx,
>      AVFrame *frame = data;
>      int ret, nb_blocks, offset = 0;
>
> +    if (avpkt->size < 2)
> +        return AVERROR_INVALIDDATA;
> +
>

Why not 1?
Or maybe 3?
Or maybe 42?

Random numbers to fix random samples are just absurd.

Kieran
Michael Niedermayer May 15, 2019, 3:53 p.m.
On Tue, May 14, 2019 at 08:52:27PM +0100, Kieran Kunhya wrote:
> On Tue, 14 May 2019 at 20:42, Michael Niedermayer <michael@niedermayer.cc>
> wrote:
> 
> > Fixes: Timeout (33sec -> 78ms)
> > Fixes:
> > 14668/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LSCR_fuzzer-5767073352908800
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by
> > <https://github.com/google/oss-fuzz/tree/master/projects/ffmpegSigned-off-by>:
> > Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/pngdec.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
> > index 6a681be29d..78988d9e75 100644
> > --- a/libavcodec/pngdec.c
> > +++ b/libavcodec/pngdec.c
> > @@ -1535,6 +1535,9 @@ static int decode_frame_lscr(AVCodecContext *avctx,
> >      AVFrame *frame = data;
> >      int ret, nb_blocks, offset = 0;
> >
> > +    if (avpkt->size < 2)
> > +        return AVERROR_INVALIDDATA;
> > +
> >
> 
> Why not 1?

because the code reads 2 bytes next:

nb_blocks = bytestream2_get_le16(gb);


> Or maybe 3?
> Or maybe 42?

Its not checking for 3 or 42 or another number because the smallest
valid frame that our decoder accepts is 2 bytes.
In case you have a specification for LSCR, that would be interresting
to read to see if it contains more constraints which would lead to a
larger minimum size

Thanks


> 
> Random numbers to fix random samples are just absurd.
> 
> Kieran
> _______________________________________________
> 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".

Patch hide | download patch | download mbox

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 6a681be29d..78988d9e75 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -1535,6 +1535,9 @@  static int decode_frame_lscr(AVCodecContext *avctx,
     AVFrame *frame = data;
     int ret, nb_blocks, offset = 0;
 
+    if (avpkt->size < 2)
+        return AVERROR_INVALIDDATA;
+
     bytestream2_init(gb, avpkt->data, avpkt->size);
 
     if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)