diff mbox

[FFmpeg-devel,1/2] avcodec/tiff: Limit filtering to decoded data

Message ID 20181123013305.16518-1-michael@niedermayer.cc
State Accepted
Commit 90ac0e5f29ba4730cd92d3268938b3730823e52b
Headers show

Commit Message

Michael Niedermayer Nov. 23, 2018, 1:33 a.m. UTC
Fixes: Timeout
Fixes: 11068/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5698456681709568

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

Comments

Tomas Härdin Nov. 24, 2018, 10:44 a.m. UTC | #1
fre 2018-11-23 klockan 02:33 +0100 skrev Michael Niedermayer:
> Fixes: Timeout
> Fixes: 11068/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5698456681709568
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/tiff.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index 74b76c9fdf..6271c937c3 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -1421,6 +1421,7 @@ again:
>      planes = s->planar ? s->bppcount : 1;
>      for (plane = 0; plane < planes; plane++) {
>          int remaining = avpkt->size;
> +        int decoded_height;
>          stride = p->linesize[plane];
>          dst = p->data[plane];
>          for (i = 0; i < s->height; i += s->rps) {
> @@ -1448,6 +1449,8 @@ again:
>                  break;
>              }
>          }
> +        decoded_height = FFMIN(i, s->height);
> +
>          if (s->predictor == 2) {
>              if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
>                  av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
> @@ -1464,7 +1467,7 @@ again:
>                  s->avctx->pix_fmt == AV_PIX_FMT_YA16LE ||
>                  s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
>                  s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
> -                for (i = 0; i < s->height; i++) {
> +                for (i = 0; i < decoded_height; i++) {
>                      for (j = soff; j < ssize; j += 2)
>                          AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
>                      dst += stride;
> @@ -1475,13 +1478,13 @@ again:
>                         s->avctx->pix_fmt == AV_PIX_FMT_YA16BE ||
>                         s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
>                         s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
> -                for (i = 0; i < s->height; i++) {
> +                for (i = 0; i < decoded_height; i++) {
>                      for (j = soff; j < ssize; j += 2)
>                          AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
>                      dst += stride;
>                  }
>              } else {
> -                for (i = 0; i < s->height; i++) {
> +                for (i = 0; i < decoded_height; i++) {
>                      for (j = soff; j < ssize; j++)
>                          dst[j] += dst[j - soff];
>                      dst += stride;

Looks OK

/Tomas
Michael Niedermayer Nov. 25, 2018, 12:22 a.m. UTC | #2
On Sat, Nov 24, 2018 at 11:44:42AM +0100, Tomas Härdin wrote:
> fre 2018-11-23 klockan 02:33 +0100 skrev Michael Niedermayer:
> > Fixes: Timeout
> > Fixes: 11068/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_TIFF_fuzzer-5698456681709568
> > 
> > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/tiff.c | 9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> > index 74b76c9fdf..6271c937c3 100644
> > --- a/libavcodec/tiff.c
> > +++ b/libavcodec/tiff.c
> > @@ -1421,6 +1421,7 @@ again:
> >      planes = s->planar ? s->bppcount : 1;
> >      for (plane = 0; plane < planes; plane++) {
> >          int remaining = avpkt->size;
> > +        int decoded_height;
> >          stride = p->linesize[plane];
> >          dst = p->data[plane];
> >          for (i = 0; i < s->height; i += s->rps) {
> > @@ -1448,6 +1449,8 @@ again:
> >                  break;
> >              }
> >          }
> > +        decoded_height = FFMIN(i, s->height);
> > +
> >          if (s->predictor == 2) {
> >              if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
> >                  av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
> > @@ -1464,7 +1467,7 @@ again:
> >                  s->avctx->pix_fmt == AV_PIX_FMT_YA16LE ||
> >                  s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
> >                  s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
> > -                for (i = 0; i < s->height; i++) {
> > +                for (i = 0; i < decoded_height; i++) {
> >                      for (j = soff; j < ssize; j += 2)
> >                          AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
> >                      dst += stride;
> > @@ -1475,13 +1478,13 @@ again:
> >                         s->avctx->pix_fmt == AV_PIX_FMT_YA16BE ||
> >                         s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
> >                         s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
> > -                for (i = 0; i < s->height; i++) {
> > +                for (i = 0; i < decoded_height; i++) {
> >                      for (j = soff; j < ssize; j += 2)
> >                          AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
> >                      dst += stride;
> >                  }
> >              } else {
> > -                for (i = 0; i < s->height; i++) {
> > +                for (i = 0; i < decoded_height; i++) {
> >                      for (j = soff; j < ssize; j++)
> >                          dst[j] += dst[j - soff];
> >                      dst += stride;
> 
> Looks OK

will apply

thanks

[...]
diff mbox

Patch

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 74b76c9fdf..6271c937c3 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1421,6 +1421,7 @@  again:
     planes = s->planar ? s->bppcount : 1;
     for (plane = 0; plane < planes; plane++) {
         int remaining = avpkt->size;
+        int decoded_height;
         stride = p->linesize[plane];
         dst = p->data[plane];
         for (i = 0; i < s->height; i += s->rps) {
@@ -1448,6 +1449,8 @@  again:
                 break;
             }
         }
+        decoded_height = FFMIN(i, s->height);
+
         if (s->predictor == 2) {
             if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
                 av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
@@ -1464,7 +1467,7 @@  again:
                 s->avctx->pix_fmt == AV_PIX_FMT_YA16LE ||
                 s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
                 s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
-                for (i = 0; i < s->height; i++) {
+                for (i = 0; i < decoded_height; i++) {
                     for (j = soff; j < ssize; j += 2)
                         AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
                     dst += stride;
@@ -1475,13 +1478,13 @@  again:
                        s->avctx->pix_fmt == AV_PIX_FMT_YA16BE ||
                        s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
                        s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
-                for (i = 0; i < s->height; i++) {
+                for (i = 0; i < decoded_height; i++) {
                     for (j = soff; j < ssize; j += 2)
                         AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
                     dst += stride;
                 }
             } else {
-                for (i = 0; i < s->height; i++) {
+                for (i = 0; i < decoded_height; i++) {
                     for (j = soff; j < ssize; j++)
                         dst[j] += dst[j - soff];
                     dst += stride;