diff options
author | Dale Curtis <dalecurtis@chromium.org> | 2024-07-30 23:12:21 +0000 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2024-09-01 12:42:20 +0200 |
commit | 7753a9d62725d5bd8313e2d249acbe1c8af79ab1 (patch) | |
tree | 8753e5599beb63228a285da62eb6aaa8646e9cec /libavcodec/avcodec.c | |
parent | 0a780d3076fe44fe6d641e84e291b567fca29999 (diff) | |
download | ffmpeg-7753a9d62725d5bd8313e2d249acbe1c8af79ab1.tar.gz |
lavc: Check codec_whitelist early in avcodec_open2()
This ensures that if a codec isn't on codec_whitelist, trying to open it
will not trigger ff_codec_close(), which could invalidate useful
information still present in the context.
Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/avcodec.c')
-rw-r--r-- | libavcodec/avcodec.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 6065f1b689..765328660b 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -174,6 +174,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); + if ((ret = av_opt_set_dict(avctx, options)) < 0) + return ret; + + if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) { + av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist); + return AVERROR(EINVAL); + } + avci = av_codec_is_decoder(codec) ? ff_decode_internal_alloc() : ff_encode_internal_alloc(); @@ -207,14 +215,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } else { avctx->priv_data = NULL; } - if ((ret = av_opt_set_dict(avctx, options)) < 0) - goto free_and_end; - - if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) { - av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist); - ret = AVERROR(EINVAL); - goto free_and_end; - } // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height && |