X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Ffic.c;h=457d74d7cda855715330e598e8fd04851ab7cb2f;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=c288c9771bfab95cec544aa57b25e8e8dfabb86c;hpb=768b07e3bca7e81d2f9c60badb3973d3d88481dc;p=ffmpeg diff --git a/libavcodec/fic.c b/libavcodec/fic.c index c288c9771bf..457d74d7cda 100644 --- a/libavcodec/fic.c +++ b/libavcodec/fic.c @@ -22,6 +22,7 @@ */ #include "libavutil/common.h" +#include "libavutil/mem_internal.h" #include "libavutil/opt.h" #include "avcodec.h" #include "internal.h" @@ -139,6 +140,9 @@ static int fic_decode_block(FICContext *ctx, GetBitContext *gb, { int i, num_coeff; + if (get_bits_left(gb) < 8) + return AVERROR_INVALIDDATA; + /* Is it a skip block? */ if (get_bits1(gb)) { *is_p = 1; @@ -173,9 +177,11 @@ static int fic_decode_slice(AVCodecContext *avctx, void *tdata) int slice_h = tctx->slice_h; int src_size = tctx->src_size; int y_off = tctx->y_off; - int x, y, p; + int x, y, p, ret; - init_get_bits(&gb, src, src_size * 8); + ret = init_get_bits8(&gb, src, src_size); + if (ret < 0) + return ret; for (p = 0; p < 3; p++) { int stride = ctx->frame->linesize[p]; @@ -273,7 +279,7 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, int skip_cursor = ctx->skip_cursor; uint8_t *sdata; - if ((ret = ff_reget_buffer(avctx, ctx->frame)) < 0) + if ((ret = ff_reget_buffer(avctx, ctx->frame, 0)) < 0) return ret; /* Header + at least one slice (4) */ @@ -351,7 +357,7 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, sdata = src + tsize + FIC_HEADER_SIZE + 4 * nslices; msize = avpkt->size - nslices * 4 - tsize - FIC_HEADER_SIZE; - if (msize <= 0) { + if (msize <= ctx->aligned_width/8 * (ctx->aligned_height/8) / 8) { av_log(avctx, AV_LOG_ERROR, "Not enough frame data to decode.\n"); return AVERROR_INVALIDDATA; } @@ -380,6 +386,8 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, slice_h = FFALIGN(avctx->height - ctx->slice_h * (nslices - 1), 16); } else { slice_size = AV_RB32(src + tsize + FIC_HEADER_SIZE + slice * 4 + 4); + if (slice_size < slice_off) + return AVERROR_INVALIDDATA; } if (slice_size < slice_off || slice_size > msize) @@ -414,7 +422,7 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, } /* Make sure we use a user-supplied buffer. */ - if ((ret = ff_reget_buffer(avctx, ctx->final_frame)) < 0) { + if ((ret = ff_reget_buffer(avctx, ctx->final_frame, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "Could not make frame writable.\n"); return ret; } @@ -469,13 +477,13 @@ static const AVOption options[] = { }; static const AVClass fic_decoder_class = { - .class_name = "FIC encoder", + .class_name = "FIC decoder", .item_name = av_default_item_name, .option = options, .version = LIBAVUTIL_VERSION_INT, }; -AVCodec ff_fic_decoder = { +const AVCodec ff_fic_decoder = { .name = "fic", .long_name = NULL_IF_CONFIG_SMALL("Mirillis FIC"), .type = AVMEDIA_TYPE_VIDEO,