diff mbox series

[FFmpeg-devel] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL

Message ID 20200726214517.13989-1-michael@niedermayer.cc
State Accepted
Commit 6ea8f03bf4b7bca2f4db28ea57696584e2560e20
Headers show
Series [FFmpeg-devel] avcodec/jpeg2000dec: Move reslevelno check before use in case JPEG2000_PGOD_RPCL | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer July 26, 2020, 9:45 p.m. UTC
Fixes: division by zero
Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064

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

Comments

Gautam Ramakrishnan July 27, 2020, 4:18 a.m. UTC | #1
On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> Fixes: division by zero
> Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
>
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/jpeg2000dec.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> index a470cf47da..b168e52db6 100644
> --- a/libavcodec/jpeg2000dec.c
> +++ b/libavcodec/jpeg2000dec.c
> @@ -1401,12 +1401,12 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
>                          if (!s->cdx[compno] || !s->cdy[compno])
>                              return AVERROR_INVALIDDATA;
>
> -                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> -                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> -
>                          if (reslevelno >= codsty->nreslevels)
>                              continue;
>
> +                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> +                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> +
>                          if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
>                               (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
>                              continue;
> --
> 2.17.1
>
> _______________________________________________
> 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".

Looks good to me.
I guess the division by zero happens because shifting by reducedresno
overflows?
Gautam Ramakrishnan July 27, 2020, 4:25 a.m. UTC | #2
On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
<gautamramk@gmail.com> wrote:
>
> On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
> >
> > Fixes: division by zero
> > Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> >
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/jpeg2000dec.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > index a470cf47da..b168e52db6 100644
> > --- a/libavcodec/jpeg2000dec.c
> > +++ b/libavcodec/jpeg2000dec.c
> > @@ -1401,12 +1401,12 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> >                          if (!s->cdx[compno] || !s->cdy[compno])
> >                              return AVERROR_INVALIDDATA;
> >
> > -                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > -                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > -
> >                          if (reslevelno >= codsty->nreslevels)
> >                              continue;
> >
> > +                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > +                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > +
> >                          if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
> >                               (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
> >                              continue;
> > --
> > 2.17.1
> >
> > _______________________________________________
> > 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".
>
> Looks good to me.
> I guess the division by zero happens because shifting by reducedresno
> overflows?
>
> --
> -------------
> Gautam |
Just realized, this might happen in one more place, shall send a
patch for the same.
Michael Niedermayer July 27, 2020, 8:16 a.m. UTC | #3
On Mon, Jul 27, 2020 at 09:55:31AM +0530, Gautam Ramakrishnan wrote:
> On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
> <gautamramk@gmail.com> wrote:
> >
> > On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
> > <michael@niedermayer.cc> wrote:
> > >
> > > Fixes: division by zero
> > > Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > > Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> > >
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >  libavcodec/jpeg2000dec.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > > index a470cf47da..b168e52db6 100644
> > > --- a/libavcodec/jpeg2000dec.c
> > > +++ b/libavcodec/jpeg2000dec.c
> > > @@ -1401,12 +1401,12 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> > >                          if (!s->cdx[compno] || !s->cdy[compno])
> > >                              return AVERROR_INVALIDDATA;
> > >
> > > -                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > > -                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > > -
> > >                          if (reslevelno >= codsty->nreslevels)
> > >                              continue;
> > >
> > > +                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > > +                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > > +
> > >                          if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
> > >                               (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
> > >                              continue;
> > > --
> > > 2.17.1
> > >
> > > _______________________________________________
> > > 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".
> >
> > Looks good to me.
> > I guess the division by zero happens because shifting by reducedresno
> > overflows?

yes

> >
> > --
> > -------------
> > Gautam |
> Just realized, this might happen in one more place, shall send a
> patch for the same.

yes

thx

[...]
Gautam Ramakrishnan July 27, 2020, 12:04 p.m. UTC | #4
On Mon, Jul 27, 2020 at 1:46 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Mon, Jul 27, 2020 at 09:55:31AM +0530, Gautam Ramakrishnan wrote:
> > On Mon, Jul 27, 2020 at 9:48 AM Gautam Ramakrishnan
> > <gautamramk@gmail.com> wrote:
> > >
> > > On Mon, Jul 27, 2020 at 3:16 AM Michael Niedermayer
> > > <michael@niedermayer.cc> wrote:
> > > >
> > > > Fixes: division by zero
> > > > Fixes: 24201/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5665813827420160
> > > > Fixes: 24245/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-6285831682392064
> > > >
> > > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > > ---
> > > >  libavcodec/jpeg2000dec.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
> > > > index a470cf47da..b168e52db6 100644
> > > > --- a/libavcodec/jpeg2000dec.c
> > > > +++ b/libavcodec/jpeg2000dec.c
> > > > @@ -1401,12 +1401,12 @@ static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
> > > >                          if (!s->cdx[compno] || !s->cdy[compno])
> > > >                              return AVERROR_INVALIDDATA;
> > > >
> > > > -                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > > > -                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > > > -
> > > >                          if (reslevelno >= codsty->nreslevels)
> > > >                              continue;
> > > >
> > > > +                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
> > > > +                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
> > > > +
> > > >                          if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
> > > >                               (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
> > > >                              continue;
> > > > --
> > > > 2.17.1
> > > >
> > > > _______________________________________________
> > > > 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".
> > >
> > > Looks good to me.
> > > I guess the division by zero happens because shifting by reducedresno
> > > overflows?
>
> yes
>
> > >
> > > --
> > > -------------
> > > Gautam |
> > Just realized, this might happen in one more place, shall send a
> > patch for the same.
>
> yes
Went through the code again, looks like this would not occur in other cases.
The other loops take into account whether reslvlno < codsty->nreslevels

I think this might be the only patch necessary
>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Dictatorship naturally arises out of democracy, and the most aggravated
> form of tyranny and slavery out of the most extreme liberty. -- Plato
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavcodec/jpeg2000dec.c b/libavcodec/jpeg2000dec.c
index a470cf47da..b168e52db6 100644
--- a/libavcodec/jpeg2000dec.c
+++ b/libavcodec/jpeg2000dec.c
@@ -1401,12 +1401,12 @@  static int jpeg2000_decode_packets_po_iteration(Jpeg2000DecoderContext *s, Jpeg2
                         if (!s->cdx[compno] || !s->cdy[compno])
                             return AVERROR_INVALIDDATA;
 
-                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
-                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
-
                         if (reslevelno >= codsty->nreslevels)
                             continue;
 
+                        trx0 = ff_jpeg2000_ceildiv(tile->coord[0][0], s->cdx[compno] << reducedresno);
+                        try0 = ff_jpeg2000_ceildiv(tile->coord[1][0], s->cdy[compno] << reducedresno);
+
                         if (!(y % ((uint64_t)s->cdy[compno] << (rlevel->log2_prec_height + reducedresno)) == 0 ||
                              (y == tile->coord[1][0] && (try0 << reducedresno) % (1U << (reducedresno + rlevel->log2_prec_height)))))
                             continue;