From 53d74e6a0f6589ac91eda4d32ee26cbfbec4b24a Mon Sep 17 00:00:00 2001
From: Dale Curtis <dalecurtis@chromium.org>
Date: Mon, 29 Jul 2024 17:14:31 +0000
Subject: [PATCH] Check codec_whitelist before reinitializing AVCtx.priv_data.

This ensures that if a codec isn't on codec_whitelist, its VUI
information can still be populated during find_stream_info()
via parsers.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
---
 libavcodec/avcodec.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 214dca4566..182a727673 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -190,6 +190,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         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;
+    }
+
     if (codec2->priv_data_size > 0) {
         if (!avctx->priv_data) {
             avctx->priv_data = av_mallocz(codec2->priv_data_size);
@@ -210,12 +216,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
     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 &&
           (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {
-- 
2.46.0.rc1.232.g9752f9e123-goog

