diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2021-03-16 19:16:36 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2021-03-20 01:43:55 +0100 |
commit | 02e43c00ed1e466567bcad47e7b28ca32ed5cffc (patch) | |
tree | f9d6ba59e45a8bd7f0d8bce42f877a085318aa9c /libavcodec/avcodec.c | |
parent | c361fa9e215cf21fb0e5b3395d675aec3d216719 (diff) | |
download | ffmpeg-02e43c00ed1e466567bcad47e7b28ca32ed5cffc.tar.gz |
avcodec/avcodec: Check earlier for codec id/type mismatch
These fields can't be set via AVOptions, ergo one can check them before
having allocated anything.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/avcodec.c')
-rw-r--r-- | libavcodec/avcodec.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 34ab793490..1e40e2298b 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -163,6 +163,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (!codec) codec = avctx->codec; + if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && + avctx->codec_id == AV_CODEC_ID_NONE) { + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + } + if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type && + avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { + av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); + return AVERROR(EINVAL); + } + avctx->codec = codec; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -281,18 +293,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code goto free_and_end; } - avctx->codec = codec; - if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) && - avctx->codec_id == AV_CODEC_ID_NONE) { - avctx->codec_type = codec->type; - avctx->codec_id = codec->id; - } - if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type - && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { - av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } avctx->frame_number = 0; avctx->codec_descriptor = avcodec_descriptor_get(avctx->codec_id); |