]> git.sesse.net Git - ffmpeg/commitdiff
dds: validate compressed source buffer size
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Wed, 11 Nov 2015 00:15:55 +0000 (01:15 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Thu, 12 Nov 2015 03:39:14 +0000 (04:39 +0100)
A too small buffer will cause segfaults somewhere below
decompress_texture_thread.

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

index 0f045d6a07860b1ce6d9cf4730d508ff55ca9ae7..219612480f12880a7dfa1f8ed6d143192f8a7341 100644 (file)
@@ -642,9 +642,18 @@ static int dds_decode(AVCodecContext *avctx, void *data,
         return ret;
 
     if (ctx->compressed) {
+        int size = (avctx->coded_height / TEXTURE_BLOCK_H) *
+                   (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->tex_ratio;
         ctx->slice_count = av_clip(avctx->thread_count, 1,
                                    avctx->coded_height / TEXTURE_BLOCK_H);
 
+        if (bytestream2_get_bytes_left(gbc) < size) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Compressed Buffer is too small (%d < %d).\n",
+                   bytestream2_get_bytes_left(gbc), size);
+            return AVERROR_INVALIDDATA;
+        }
+
         /* Use the decompress function on the texture, one block per thread. */
         ctx->tex_data = gbc->buffer;
         avctx->execute2(avctx, decompress_texture_thread, frame, NULL, ctx->slice_count);