tiffdec: check overread for packbits
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 15 Apr 2012 18:19:42 +0000 (20:19 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 15 Apr 2012 18:20:43 +0000 (20:20 +0200)
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/tiff.c

index 8de1ebd..a30e1a9 100644 (file)
@@ -253,6 +253,10 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
             break;
         case TIFF_PACKBITS:
             for (pixels = 0; pixels < width;) {
+                if (ssrc + size - src < 2) {
+                    av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
+                    return AVERROR_INVALIDDATA;
+                }
                 code = (int8_t) * src++;
                 if (code >= 0) {
                     code++;
@@ -261,6 +265,10 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
                                "Copy went out of bounds\n");
                         return -1;
                     }
+                    if (ssrc + size - src < code) {
+                        av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
+                        return AVERROR_INVALIDDATA;
+                    }
                     horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8),
                                     dst, 1, src, 0, code, pixels);
                     src += code;