tiff: do not overread the source buffer
authorLuca Barbato <lu_zero@gentoo.org>
Mon, 3 Jun 2013 02:53:02 +0000 (04:53 +0200)
committerLuca Barbato <lu_zero@gentoo.org>
Fri, 7 Jun 2013 15:23:53 +0000 (17:23 +0200)
At least 2 bytes from the source are read every loop.

Reported-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
libavcodec/tiff.c

index edef830..735eafe 100644 (file)
@@ -224,10 +224,13 @@ 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)
+                    return AVERROR_INVALIDDATA;
                 code = (int8_t) *src++;
                 if (code >= 0) {
                     code++;
-                    if (pixels + code > width) {
+                    if (pixels + code > width ||
+                        ssrc + size - src < code) {
                         av_log(s->avctx, AV_LOG_ERROR,
                                "Copy went out of bounds\n");
                         return AVERROR_INVALIDDATA;