File ffmpeg-CVE-2020-22037.patch of Package ffmpeg.32491

diff --unified --recursive --text --new-file --color ffmpeg-3.4.2.old/libavcodec/frame_thread_encoder.c ffmpeg-3.4.2.new/libavcodec/frame_thread_encoder.c
--- ffmpeg-3.4.2.old/libavcodec/frame_thread_encoder.c	2021-10-13 13:48:52.875605224 +0800
+++ ffmpeg-3.4.2.new/libavcodec/frame_thread_encoder.c	2021-10-13 16:14:36.408676821 +0800
@@ -117,7 +117,7 @@
 int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){
     int i=0;
     ThreadContext *c;
-
+    AVCodecContext *thread_avctx = NULL;
 
     if(   !(avctx->thread_type & FF_THREAD_FRAME)
        || !(avctx->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY))
@@ -195,16 +195,17 @@
         AVDictionary *tmp = NULL;
         int ret;
         void *tmpv;
-        AVCodecContext *thread_avctx = avcodec_alloc_context3(avctx->codec);
+        thread_avctx = avcodec_alloc_context3(avctx->codec);
         if(!thread_avctx)
             goto fail;
         tmpv = thread_avctx->priv_data;
         *thread_avctx = *avctx;
+        thread_avctx->priv_data = tmpv;
+        thread_avctx->internal = NULL;
+        thread_avctx->hw_frames_ctx = NULL;
         ret = av_opt_copy(thread_avctx, avctx);
         if (ret < 0)
             goto fail;
-        thread_avctx->priv_data = tmpv;
-        thread_avctx->internal = NULL;
         if (avctx->codec->priv_class) {
             int ret = av_opt_copy(thread_avctx->priv_data, avctx->priv_data);
             if (ret < 0)
@@ -232,6 +233,8 @@
 
     return 0;
 fail:
+    avcodec_close(thread_avctx);
+    av_freep(&thread_avctx);
     avctx->thread_count = i;
     av_log(avctx, AV_LOG_ERROR, "ff_frame_thread_encoder_init failed\n");
     ff_frame_thread_encoder_free(avctx);
diff --unified --recursive --text --new-file --color ffmpeg-3.4.2.old/libavcodec/frame_thread_encoder.h ffmpeg-3.4.2.new/libavcodec/frame_thread_encoder.h
--- ffmpeg-3.4.2.old/libavcodec/frame_thread_encoder.h	2021-10-13 13:48:52.895605197 +0800
+++ ffmpeg-3.4.2.new/libavcodec/frame_thread_encoder.h	2021-10-13 16:15:54.158631405 +0800
@@ -23,6 +23,10 @@
 
 #include "avcodec.h"
 
+/**
+ * Initialize frame thread encoder.
+ * @note hardware encoders are not supported
+ */
 int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options);
 void ff_frame_thread_encoder_free(AVCodecContext *avctx);
 int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr);
openSUSE Build Service is sponsored by