X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fsanm.c;h=dddc2c871b02c3a5b441c76b051f00217db3f098;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=811fd2188e22fd9cbd53cd207251efa943df784b;hpb=23ce57af3ad684363881cdd66d5724f40963a65c;p=ffmpeg diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index 811fd2188e2..dddc2c871b0 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -491,6 +491,11 @@ static av_cold int decode_init(AVCodecContext *avctx) ctx->avctx = avctx; ctx->version = !avctx->extradata_size; + // early sanity check before allocations to avoid need for deallocation code. + if (!ctx->version && avctx->extradata_size < 1026) { + av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n"); + return AVERROR_INVALIDDATA; + } avctx->pix_fmt = ctx->version ? AV_PIX_FMT_RGB565 : AV_PIX_FMT_PAL8; @@ -506,11 +511,6 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!ctx->version) { int i; - if (avctx->extradata_size < 1026) { - av_log(avctx, AV_LOG_ERROR, "Not enough extradata.\n"); - return AVERROR_INVALIDDATA; - } - ctx->subversion = AV_RL16(avctx->extradata); for (i = 0; i < PALETTE_SIZE; i++) ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4); @@ -1358,8 +1358,10 @@ static int read_frame_header(SANMVideoContext *ctx, SANMFrameHeader *hdr) static void fill_frame(uint16_t *pbuf, int buf_size, uint16_t color) { - while (buf_size--) + if (buf_size--) { *pbuf++ = color; + av_memcpy_backptr((uint8_t*)pbuf, 2, 2*buf_size); + } } static int copy_output(SANMVideoContext *ctx, SANMFrameHeader *hdr) @@ -1513,7 +1515,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, return pkt->size; } -AVCodec ff_sanm_decoder = { +const AVCodec ff_sanm_decoder = { .name = "sanm", .long_name = NULL_IF_CONFIG_SMALL("LucasArts SANM/Smush video"), .type = AVMEDIA_TYPE_VIDEO,