]> git.sesse.net Git - ffmpeg/commitdiff
dds: validate source buffer size before copying
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Wed, 11 Nov 2015 00:14:57 +0000 (01:14 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 12 Nov 2015 03:39:14 +0000 (04:39 +0100)
If it is too small av_image_copy_plane segfaults.

Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
libavcodec/dds.c

index 04b1dd2de8cc5bb5531da0fb5535e746e0d6521f..0f045d6a07860b1ce6d9cf4730d508ff55ca9ae7 100644 (file)
@@ -668,6 +668,12 @@ static int dds_decode(AVCodecContext *avctx, void *data,
             frame->palette_has_changed = 1;
         }
 
+        if (bytestream2_get_bytes_left(gbc) < frame->height * linesize) {
+            av_log(avctx, AV_LOG_ERROR, "Buffer is too small (%d < %d).\n",
+                   bytestream2_get_bytes_left(gbc), frame->height * linesize);
+            return AVERROR_INVALIDDATA;
+        }
+
         av_image_copy_plane(frame->data[0], frame->linesize[0],
                             gbc->buffer, linesize,
                             linesize, frame->height);