X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fdxtory.c;h=4dd675316b8fbdcc4b06231869f3219360680646;hb=67c4405fac3f227126a6233daab629f322abe4d2;hp=285ca38efb8b48875c09130cc2cf65c7e796adb6;hpb=fb4a12cda4033f2f3d3d1039739f6e0e6f9afb82;p=ffmpeg diff --git a/libavcodec/dxtory.c b/libavcodec/dxtory.c index 285ca38efb8..4dd675316b8 100644 --- a/libavcodec/dxtory.c +++ b/libavcodec/dxtory.c @@ -272,10 +272,11 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, setup_lru_func setup_lru, enum AVPixelFormat fmt) { - GetByteContext gb; + GetByteContext gb, gb_check; GetBitContext gb2; int nslices, slice, line = 0; uint32_t off, slice_size; + uint64_t off_check; uint8_t lru[3][8]; int ret; @@ -283,6 +284,19 @@ static int dxtory_decode_v2(AVCodecContext *avctx, AVFrame *pic, if (ret < 0) return ret; + off_check = off; + gb_check = gb; + for (slice = 0; slice < nslices; slice++) { + slice_size = bytestream2_get_le32(&gb_check); + + if (slice_size <= 16 + (avctx->height * avctx->width / (8 * nslices))) + return AVERROR_INVALIDDATA; + off_check += slice_size; + } + + if (off_check - avctx->discard_damaged_percentage*off_check/100 > src_size) + return AVERROR_INVALIDDATA; + avctx->pix_fmt = fmt; if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) return ret;