diff mbox series

[FFmpeg-devel,2/4] avcodec/apedec: Use 64bit in 4/3 calculation in do_apply_filter()

Message ID 20211203171956.12231-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/4] avformat/mov: Disallow duplicate smdm
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Michael Niedermayer Dec. 3, 2021, 5:19 p.m. UTC
Fixes: Integer overflow
Fixes: 40973/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-6739312704618496

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

Comments

Anton Khirnov Dec. 6, 2021, 10:23 a.m. UTC | #1
Quoting Michael Niedermayer (2021-12-03 18:19:54)
> Fixes: Integer overflow
> Fixes: 40973/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-6739312704618496
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/apedec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> index 9c723f29977..5c3261cf5cb 100644
> --- a/libavcodec/apedec.c
> +++ b/libavcodec/apedec.c
> @@ -1337,7 +1337,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
>              absres = FFABSU(res);
>              if (absres)
>                  *f->adaptcoeffs = APESIGN(res) *
> -                                  (8 << ((absres > f->avg * 3LL) + (absres > (f->avg + f->avg / 3))));
> +                                  (8 << ((absres > f->avg * 3LL) + (absres > ((int64_t)f->avg + f->avg / 3))));
>                  /* equivalent to the following code
>                      if (absres <= f->avg * 4 / 3)
>                          *f->adaptcoeffs = APESIGN(res) * 8;
> -- 
> 2.17.1

Does this not assume a 32bit int?
Michael Niedermayer Dec. 6, 2021, 11:01 a.m. UTC | #2
On Mon, Dec 06, 2021 at 11:23:12AM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-12-03 18:19:54)
> > Fixes: Integer overflow
> > Fixes: 40973/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-6739312704618496
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/apedec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> > index 9c723f29977..5c3261cf5cb 100644
> > --- a/libavcodec/apedec.c
> > +++ b/libavcodec/apedec.c
> > @@ -1337,7 +1337,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
> >              absres = FFABSU(res);
> >              if (absres)
> >                  *f->adaptcoeffs = APESIGN(res) *
> > -                                  (8 << ((absres > f->avg * 3LL) + (absres > (f->avg + f->avg / 3))));
> > +                                  (8 << ((absres > f->avg * 3LL) + (absres > ((int64_t)f->avg + f->avg / 3))));
> >                  /* equivalent to the following code
> >                      if (absres <= f->avg * 4 / 3)
> >                          *f->adaptcoeffs = APESIGN(res) * 8;
> > -- 
> > 2.17.1
> 
> Does this not assume a 32bit int?

hmm
you mean avg could overflow 64bit ?
iam not sure that can happen but
we could make avg int32 or uint32 ?

thx

[...]
Anton Khirnov Dec. 6, 2021, 2:50 p.m. UTC | #3
Quoting Michael Niedermayer (2021-12-06 12:01:09)
> On Mon, Dec 06, 2021 at 11:23:12AM +0100, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2021-12-03 18:19:54)
> > > Fixes: Integer overflow
> > > Fixes: 40973/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-6739312704618496
> > > 
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/apedec.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> > > index 9c723f29977..5c3261cf5cb 100644
> > > --- a/libavcodec/apedec.c
> > > +++ b/libavcodec/apedec.c
> > > @@ -1337,7 +1337,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
> > >              absres = FFABSU(res);
> > >              if (absres)
> > >                  *f->adaptcoeffs = APESIGN(res) *
> > > -                                  (8 << ((absres > f->avg * 3LL) + (absres > (f->avg + f->avg / 3))));
> > > +                                  (8 << ((absres > f->avg * 3LL) + (absres > ((int64_t)f->avg + f->avg / 3))));
> > >                  /* equivalent to the following code
> > >                      if (absres <= f->avg * 4 / 3)
> > >                          *f->adaptcoeffs = APESIGN(res) * 8;
> > > -- 
> > > 2.17.1
> > 
> > Does this not assume a 32bit int?
> 
> hmm
> you mean avg could overflow 64bit ?
> iam not sure that can happen but
> we could make avg int32 or uint32 ?

Seems it cannot, but it's not completely obvious. So changing it to
uint32 might make sense, since it cannot be negative.
Michael Niedermayer Dec. 9, 2021, 12:37 p.m. UTC | #4
On Mon, Dec 06, 2021 at 03:50:34PM +0100, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2021-12-06 12:01:09)
> > On Mon, Dec 06, 2021 at 11:23:12AM +0100, Anton Khirnov wrote:
> > > Quoting Michael Niedermayer (2021-12-03 18:19:54)
> > > > Fixes: Integer overflow
> > > > Fixes: 40973/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_APE_fuzzer-6739312704618496
> > > > 
> > > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > > ---
> > > >  libavcodec/apedec.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
> > > > index 9c723f29977..5c3261cf5cb 100644
> > > > --- a/libavcodec/apedec.c
> > > > +++ b/libavcodec/apedec.c
> > > > @@ -1337,7 +1337,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
> > > >              absres = FFABSU(res);
> > > >              if (absres)
> > > >                  *f->adaptcoeffs = APESIGN(res) *
> > > > -                                  (8 << ((absres > f->avg * 3LL) + (absres > (f->avg + f->avg / 3))));
> > > > +                                  (8 << ((absres > f->avg * 3LL) + (absres > ((int64_t)f->avg + f->avg / 3))));
> > > >                  /* equivalent to the following code
> > > >                      if (absres <= f->avg * 4 / 3)
> > > >                          *f->adaptcoeffs = APESIGN(res) * 8;
> > > > -- 
> > > > 2.17.1
> > > 
> > > Does this not assume a 32bit int?
> > 
> > hmm
> > you mean avg could overflow 64bit ?
> > iam not sure that can happen but
> > we could make avg int32 or uint32 ?
> 
> Seems it cannot, but it's not completely obvious. So changing it to
> uint32 might make sense, since it cannot be negative.

ok will change it to uint32

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 9c723f29977..5c3261cf5cb 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1337,7 +1337,7 @@  static void do_apply_filter(APEContext *ctx, int version, APEFilter *f,
             absres = FFABSU(res);
             if (absres)
                 *f->adaptcoeffs = APESIGN(res) *
-                                  (8 << ((absres > f->avg * 3LL) + (absres > (f->avg + f->avg / 3))));
+                                  (8 << ((absres > f->avg * 3LL) + (absres > ((int64_t)f->avg + f->avg / 3))));
                 /* equivalent to the following code
                     if (absres <= f->avg * 4 / 3)
                         *f->adaptcoeffs = APESIGN(res) * 8;