diff mbox series

[FFmpeg-devel,1/6] avcodec/utils: Check earlier for codec id/type mismatch

Message ID 20210316203100.528950-1-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/6] avcodec/utils: Check earlier for codec id/type mismatch
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 16, 2021, 8:30 p.m. UTC
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>
---
 libavcodec/utils.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Andreas Rheinhardt March 19, 2021, 1:51 a.m. UTC | #1
Andreas Rheinhardt:
> 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>
> ---
>  libavcodec/utils.c | 24 ++++++++++++------------
>  1 file changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 71dbcb19d8..2bc556c1d9 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -564,6 +564,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);
>  
> @@ -682,18 +694,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);
>  
> 
Will apply tonight unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 71dbcb19d8..2bc556c1d9 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -564,6 +564,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);
 
@@ -682,18 +694,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);