summaryrefslogtreecommitdiff
path: root/libavcodec/dds.c
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-11-11 01:15:55 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-11-12 04:39:14 +0100
commit29b17528612c8b0f66e6982ab48cc0816e41f36f (patch)
treee11fcb2b0ecfef30ab2a730abf4e071f4e56a02c /libavcodec/dds.c
parente6459c655e110cd9acb5d0658d89c415eaca847b (diff)
dds: validate compressed source buffer size
A too small buffer will cause segfaults somewhere below decompress_texture_thread. Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Diffstat (limited to 'libavcodec/dds.c')
-rw-r--r--libavcodec/dds.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libavcodec/dds.c b/libavcodec/dds.c
index 0f045d6a07..219612480f 100644
--- a/libavcodec/dds.c
+++ b/libavcodec/dds.c
@@ -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);