summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-05-13 18:09:04 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-01-16 00:35:12 +0100
commite438fd3be905cefdf75d9cc5a632ded4dc043be5 (patch)
treedc28ccf1495509af178d88fce565b7a826fd82e8
parent3d380ffde9af31152b1ddac47fa09521e0ae3d57 (diff)
downloadffmpeg-e438fd3be905cefdf75d9cc5a632ded4dc043be5.tar.gz
avcodec/lcldec: Check that dimensions are a multiple of the subsample factors
Other dimensions would not work correctly currently, also ask for a sample for files that fail this check. This fixes an integer overflow leading to out of array accesses. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 1e00bbb10cbde3da03a1e744265ce6def9ae4c56) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/lcldec.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/libavcodec/lcldec.c b/libavcodec/lcldec.c
index f8d45da95a..78210413bc 100644
--- a/libavcodec/lcldec.c
+++ b/libavcodec/lcldec.c
@@ -42,6 +42,7 @@
#include <stdlib.h>
#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "bytestream.h"
#include "internal.h"
@@ -491,6 +492,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
unsigned int max_basesize = FFALIGN(avctx->width, 4) *
FFALIGN(avctx->height, 4);
unsigned int max_decomp_size;
+ int subsample_h, subsample_v;
avcodec_get_frame_defaults(&c->pic);
if (avctx->extradata_size < 8) {
@@ -517,6 +519,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
max_decomp_size = max_basesize * 2;
avctx->pix_fmt = AV_PIX_FMT_YUV422P;
av_log(avctx, AV_LOG_DEBUG, "Image type is YUV 4:2:2.\n");
+ if (avctx->width % 4) {
+ return AVERROR_INVALIDDATA;
+ }
break;
case IMGTYPE_RGB24:
c->decomp_size = basesize * 3;
@@ -547,6 +552,11 @@ static av_cold int decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA;
}
+ av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &subsample_h, &subsample_v);
+ if (avctx->width % (1<<subsample_h) || avctx->height % (1<<subsample_v)) {
+ return AVERROR_INVALIDDATA;
+ }
+
/* Detect compression method */
c->compression = (int8_t)avctx->extradata[5];
switch (avctx->codec_id) {