X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fbintext.c;h=520d68a7c072c3e2c8e469a81343d55578df332e;hb=1ab74bc19354aedfb9afe71515952254753a75cc;hp=d967317671b89a008b98b7d065851d20531592a3;hpb=14fe81b3a88dfe4dbac12e8715f9a3f05b5ef1bf;p=ffmpeg diff --git a/libavcodec/bintext.c b/libavcodec/bintext.c index d967317671b..520d68a7c07 100644 --- a/libavcodec/bintext.c +++ b/libavcodec/bintext.c @@ -63,6 +63,10 @@ static av_cold int decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "not enough extradata\n"); return AVERROR_INVALIDDATA; } + if (!s->font_height) { + av_log(avctx, AV_LOG_ERROR, "invalid font height\n"); + return AVERROR_INVALIDDATA; + } } else { s->font_height = 8; s->flags = 0; @@ -93,13 +97,10 @@ static av_cold int decode_init(AVCodecContext *avctx) break; } } - if (avctx->width < FONT_WIDTH || avctx->height < s->font_height) + if (avctx->width < FONT_WIDTH || avctx->height < s->font_height) { + av_log(avctx, AV_LOG_ERROR, "Resolution too small for font.\n"); return AVERROR_INVALIDDATA; - - - s->frame = av_frame_alloc(); - if (!s->frame) - return AVERROR(ENOMEM); + } return 0; } @@ -146,8 +147,12 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *buf_end = buf+buf_size; int ret; + if ((avctx->width / FONT_WIDTH) * (avctx->height / s->font_height) / 256 > buf_size) + return AVERROR_INVALIDDATA; + + s->frame = data; s->x = s->y = 0; - if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) + if ((ret = ff_get_buffer(avctx, s->frame, 0)) < 0) return ret; s->frame->pict_type = AV_PICTURE_TYPE_I; s->frame->palette_has_changed = 1; @@ -205,56 +210,42 @@ static int decode_frame(AVCodecContext *avctx, } } - if ((ret = av_frame_ref(data, s->frame)) < 0) - return ret; *got_frame = 1; return buf_size; } -static av_cold int decode_end(AVCodecContext *avctx) -{ - XbinContext *s = avctx->priv_data; - - av_frame_free(&s->frame); - - return 0; -} - #if CONFIG_BINTEXT_DECODER -AVCodec ff_bintext_decoder = { +const AVCodec ff_bintext_decoder = { .name = "bintext", .long_name = NULL_IF_CONFIG_SMALL("Binary text"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_BINTEXT, .priv_data_size = sizeof(XbinContext), .init = decode_init, - .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1, }; #endif #if CONFIG_XBIN_DECODER -AVCodec ff_xbin_decoder = { +const AVCodec ff_xbin_decoder = { .name = "xbin", .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_XBIN, .priv_data_size = sizeof(XbinContext), .init = decode_init, - .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1, }; #endif #if CONFIG_IDF_DECODER -AVCodec ff_idf_decoder = { +const AVCodec ff_idf_decoder = { .name = "idf", .long_name = NULL_IF_CONFIG_SMALL("iCEDraw text"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_IDF, .priv_data_size = sizeof(XbinContext), .init = decode_init, - .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1, };