diff mbox

[FFmpeg-devel,3/3] avcodec/huffyuvdec: Check input buffer size

Message ID 20180131182010.8745-3-michael@niedermayer.cc
State Accepted
Commit 08c220d26cff51ca2f6896b65aebfa3accc67290
Headers show

Commit Message

Michael Niedermayer Jan. 31, 2018, 6:20 p.m. UTC
Fixes: Timeout
Fixes: 5487/clusterfuzz-testcase-4696837035393024

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

Comments

Paul B Mahol Jan. 31, 2018, 6:56 p.m. UTC | #1
On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> Fixes: Timeout
> Fixes: 5487/clusterfuzz-testcase-4696837035393024
>
> Found-by: continuous fuzzing process
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/huffyuvdec.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> index 979c4b9d5c..66357bfb40 100644
> --- a/libavcodec/huffyuvdec.c
> +++ b/libavcodec/huffyuvdec.c
> @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *got_frame,
>      AVFrame *const p = data;
>      int table_size = 0, ret;
>
> +    if (buf_size < (width * height + 7)/8)
> +        return AVERROR_INVALIDDATA;
> +

Are you sure this is enough?

Something similar you had already posted long ago.
Michael Niedermayer Feb. 1, 2018, 1:36 a.m. UTC | #2
On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
> On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > Fixes: Timeout
> > Fixes: 5487/clusterfuzz-testcase-4696837035393024
> >
> > Found-by: continuous fuzzing process
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/huffyuvdec.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> > index 979c4b9d5c..66357bfb40 100644
> > --- a/libavcodec/huffyuvdec.c
> > +++ b/libavcodec/huffyuvdec.c
> > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx, void
> > *data, int *got_frame,
> >      AVFrame *const p = data;
> >      int table_size = 0, ret;
> >
> > +    if (buf_size < (width * height + 7)/8)
> > +        return AVERROR_INVALIDDATA;
> > +
> 
> Are you sure this is enough?

I dont know if thats the only way the decoder can be made to waste
large amounts of CPU with little input data

I do belive it stops this specific class of issues though


> 
> Something similar you had already posted long ago.

for other decoders, yes. Did i forget a patch for huffyuv ?

[...]
Michael Niedermayer Feb. 4, 2018, 11:34 p.m. UTC | #3
On Thu, Feb 01, 2018 at 02:36:16AM +0100, Michael Niedermayer wrote:
> On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
> > On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > > Fixes: Timeout
> > > Fixes: 5487/clusterfuzz-testcase-4696837035393024
> > >
> > > Found-by: continuous fuzzing process
> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/huffyuvdec.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> > > index 979c4b9d5c..66357bfb40 100644
> > > --- a/libavcodec/huffyuvdec.c
> > > +++ b/libavcodec/huffyuvdec.c
> > > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx, void
> > > *data, int *got_frame,
> > >      AVFrame *const p = data;
> > >      int table_size = 0, ret;
> > >
> > > +    if (buf_size < (width * height + 7)/8)
> > > +        return AVERROR_INVALIDDATA;
> > > +
> > 
> > Are you sure this is enough?
> 
> I dont know if thats the only way the decoder can be made to waste
> large amounts of CPU with little input data
> 
> I do belive it stops this specific class of issues though
> 
> 
> > 
> > Something similar you had already posted long ago.
> 
> for other decoders, yes. Did i forget a patch for huffyuv ?

i will apply this in a few days unless someone has objections or
sees some possible imrpovment

[...]
Paul B Mahol Feb. 5, 2018, 9:04 a.m. UTC | #4
On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Thu, Feb 01, 2018 at 02:36:16AM +0100, Michael Niedermayer wrote:
>> On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
>> > On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
>> > > Fixes: Timeout
>> > > Fixes: 5487/clusterfuzz-testcase-4696837035393024
>> > >
>> > > Found-by: continuous fuzzing process
>> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> > > ---
>> > >  libavcodec/huffyuvdec.c | 3 +++
>> > >  1 file changed, 3 insertions(+)
>> > >
>> > > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
>> > > index 979c4b9d5c..66357bfb40 100644
>> > > --- a/libavcodec/huffyuvdec.c
>> > > +++ b/libavcodec/huffyuvdec.c
>> > > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx,
>> > > void
>> > > *data, int *got_frame,
>> > >      AVFrame *const p = data;
>> > >      int table_size = 0, ret;
>> > >
>> > > +    if (buf_size < (width * height + 7)/8)
>> > > +        return AVERROR_INVALIDDATA;
>> > > +
>> >
>> > Are you sure this is enough?
>>
>> I dont know if thats the only way the decoder can be made to waste
>> large amounts of CPU with little input data
>>
>> I do belive it stops this specific class of issues though
>>
>>
>> >
>> > Something similar you had already posted long ago.
>>
>> for other decoders, yes. Did i forget a patch for huffyuv ?
>
> i will apply this in a few days unless someone has objections or
> sees some possible imrpovment

Are you sure this does not break decoding of valid files?
Michael Niedermayer Feb. 5, 2018, 8:57 p.m. UTC | #5
On Mon, Feb 05, 2018 at 10:04:47AM +0100, Paul B Mahol wrote:
> On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > On Thu, Feb 01, 2018 at 02:36:16AM +0100, Michael Niedermayer wrote:
> >> On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
> >> > On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> >> > > Fixes: Timeout
> >> > > Fixes: 5487/clusterfuzz-testcase-4696837035393024
> >> > >
> >> > > Found-by: continuous fuzzing process
> >> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> >> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >> > > ---
> >> > >  libavcodec/huffyuvdec.c | 3 +++
> >> > >  1 file changed, 3 insertions(+)
> >> > >
> >> > > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> >> > > index 979c4b9d5c..66357bfb40 100644
> >> > > --- a/libavcodec/huffyuvdec.c
> >> > > +++ b/libavcodec/huffyuvdec.c
> >> > > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx,
> >> > > void
> >> > > *data, int *got_frame,
> >> > >      AVFrame *const p = data;
> >> > >      int table_size = 0, ret;
> >> > >
> >> > > +    if (buf_size < (width * height + 7)/8)
> >> > > +        return AVERROR_INVALIDDATA;
> >> > > +
> >> >
> >> > Are you sure this is enough?
> >>
> >> I dont know if thats the only way the decoder can be made to waste
> >> large amounts of CPU with little input data
> >>
> >> I do belive it stops this specific class of issues though
> >>
> >>
> >> >
> >> > Something similar you had already posted long ago.
> >>
> >> for other decoders, yes. Did i forget a patch for huffyuv ?
> >
> > i will apply this in a few days unless someone has objections or
> > sees some possible imrpovment
> 
> Are you sure this does not break decoding of valid files?

huffyuv encodes samples using huffman codes, the smallest is 1 bit so
w*h bits should be the minimum

Am i missing something ?


[...]
Paul B Mahol Feb. 8, 2018, 5:09 p.m. UTC | #6
On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> On Mon, Feb 05, 2018 at 10:04:47AM +0100, Paul B Mahol wrote:
>> On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
>> > On Thu, Feb 01, 2018 at 02:36:16AM +0100, Michael Niedermayer wrote:
>> >> On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
>> >> > On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
>> >> > > Fixes: Timeout
>> >> > > Fixes: 5487/clusterfuzz-testcase-4696837035393024
>> >> > >
>> >> > > Found-by: continuous fuzzing process
>> >> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> >> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> >> > > ---
>> >> > >  libavcodec/huffyuvdec.c | 3 +++
>> >> > >  1 file changed, 3 insertions(+)
>> >> > >
>> >> > > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
>> >> > > index 979c4b9d5c..66357bfb40 100644
>> >> > > --- a/libavcodec/huffyuvdec.c
>> >> > > +++ b/libavcodec/huffyuvdec.c
>> >> > > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx,
>> >> > > void
>> >> > > *data, int *got_frame,
>> >> > >      AVFrame *const p = data;
>> >> > >      int table_size = 0, ret;
>> >> > >
>> >> > > +    if (buf_size < (width * height + 7)/8)
>> >> > > +        return AVERROR_INVALIDDATA;
>> >> > > +
>> >> >
>> >> > Are you sure this is enough?
>> >>
>> >> I dont know if thats the only way the decoder can be made to waste
>> >> large amounts of CPU with little input data
>> >>
>> >> I do belive it stops this specific class of issues though
>> >>
>> >>
>> >> >
>> >> > Something similar you had already posted long ago.
>> >>
>> >> for other decoders, yes. Did i forget a patch for huffyuv ?
>> >
>> > i will apply this in a few days unless someone has objections or
>> > sees some possible imrpovment
>>
>> Are you sure this does not break decoding of valid files?
>
> huffyuv encodes samples using huffman codes, the smallest is 1 bit so
> w*h bits should be the minimum
>
>

ok
Michael Niedermayer Feb. 8, 2018, 10:06 p.m. UTC | #7
On Thu, Feb 08, 2018 at 06:09:46PM +0100, Paul B Mahol wrote:
> On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > On Mon, Feb 05, 2018 at 10:04:47AM +0100, Paul B Mahol wrote:
> >> On 2/5/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> >> > On Thu, Feb 01, 2018 at 02:36:16AM +0100, Michael Niedermayer wrote:
> >> >> On Wed, Jan 31, 2018 at 07:56:06PM +0100, Paul B Mahol wrote:
> >> >> > On 1/31/18, Michael Niedermayer <michael@niedermayer.cc> wrote:
> >> >> > > Fixes: Timeout
> >> >> > > Fixes: 5487/clusterfuzz-testcase-4696837035393024
> >> >> > >
> >> >> > > Found-by: continuous fuzzing process
> >> >> > > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> >> >> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >> >> > > ---
> >> >> > >  libavcodec/huffyuvdec.c | 3 +++
> >> >> > >  1 file changed, 3 insertions(+)
> >> >> > >
> >> >> > > diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
> >> >> > > index 979c4b9d5c..66357bfb40 100644
> >> >> > > --- a/libavcodec/huffyuvdec.c
> >> >> > > +++ b/libavcodec/huffyuvdec.c
> >> >> > > @@ -919,6 +919,9 @@ static int decode_frame(AVCodecContext *avctx,
> >> >> > > void
> >> >> > > *data, int *got_frame,
> >> >> > >      AVFrame *const p = data;
> >> >> > >      int table_size = 0, ret;
> >> >> > >
> >> >> > > +    if (buf_size < (width * height + 7)/8)
> >> >> > > +        return AVERROR_INVALIDDATA;
> >> >> > > +
> >> >> >
> >> >> > Are you sure this is enough?
> >> >>
> >> >> I dont know if thats the only way the decoder can be made to waste
> >> >> large amounts of CPU with little input data
> >> >>
> >> >> I do belive it stops this specific class of issues though
> >> >>
> >> >>
> >> >> >
> >> >> > Something similar you had already posted long ago.
> >> >>
> >> >> for other decoders, yes. Did i forget a patch for huffyuv ?
> >> >
> >> > i will apply this in a few days unless someone has objections or
> >> > sees some possible imrpovment
> >>
> >> Are you sure this does not break decoding of valid files?
> >
> > huffyuv encodes samples using huffman codes, the smallest is 1 bit so
> > w*h bits should be the minimum
> >
> >
> 
> ok

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index 979c4b9d5c..66357bfb40 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -919,6 +919,9 @@  static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     AVFrame *const p = data;
     int table_size = 0, ret;
 
+    if (buf_size < (width * height + 7)/8)
+        return AVERROR_INVALIDDATA;
+
     av_fast_padded_malloc(&s->bitstream_buffer,
                    &s->bitstream_buffer_size,
                    buf_size);