diff mbox

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

Message ID 20190514193839.25704-1-michael@niedermayer.cc
State Accepted
Commit c830752142bb5e052d540c429d41fb6dafe920db
Headers show

Commit Message

Michael Niedermayer May 14, 2019, 7:38 p.m. UTC
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. UTC | #1
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. UTC | #2
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".
Michael Niedermayer June 12, 2019, 7:33 a.m. UTC | #3
On Wed, May 15, 2019 at 05:53:49PM +0200, Michael Niedermayer wrote:
> 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

will apply the patch in  the next days unless there are objections


[...]
diff mbox

Patch

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)