diff options
author | Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> | 2015-11-11 00:20:18 +0100 |
---|---|---|
committer | Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> | 2015-11-26 01:35:46 +0100 |
commit | ef699b4135f48cd1524e280b59704e1b91c27864 (patch) | |
tree | 13038297be5ed74c3b09cb082a07560a2340bfd1 | |
parent | a8513826dda2a6ace68a3819eec1d9c6b1f3b98f (diff) | |
download | ffmpeg-ef699b4135f48cd1524e280b59704e1b91c27864.tar.gz |
dds: validate compressed source buffer size
A too small buffer will cause segfaults somewhere below
decompress_texture_thread.
Reviewed-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
(cherry picked from commit 9a37d476440d9edaa26e6ed946d79cedde9d9e93)
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
-rw-r--r-- | libavcodec/dds.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libavcodec/dds.c b/libavcodec/dds.c index 324e6657a6..c918cf0fa5 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); |