[FFmpeg-cvslog] avcodec/cuviddec: avoid copy of uninitialized extradata pointer

Timo Rothenpieler git at videolan.org
Thu Oct 1 22:35:00 EEST 2020


ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Thu Oct  1 21:09:34 2020 +0200| [13c74291ecfb9a080b37c796b1e10ccd3e5b413e] | committer: Timo Rothenpieler

avcodec/cuviddec: avoid copy of uninitialized extradata pointer

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=13c74291ecfb9a080b37c796b1e10ccd3e5b413e
---

 libavcodec/cuviddec.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index aab6d00c8d..2d6377bc8c 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -795,7 +795,7 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
     CUcontext cuda_ctx = NULL;
     CUcontext dummy;
     uint8_t *extradata;
-    ssize_t extradata_size;
+    int extradata_size;
     int ret = 0;
 
     enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA,
@@ -949,20 +949,21 @@ static av_cold int cuvid_decode_init(AVCodecContext *avctx)
         const AVCodecParameters *par = avctx->internal->bsf->par_out;
         extradata = par->extradata;
         extradata_size = par->extradata_size;
-    } else if (avctx->extradata_size > 0) {
+    } else {
         extradata = avctx->extradata;
         extradata_size = avctx->extradata_size;
     }
 
     ctx->cuparse_ext = av_mallocz(sizeof(*ctx->cuparse_ext)
-            + FFMAX(extradata_size - (ssize_t)sizeof(ctx->cuparse_ext->raw_seqhdr_data), 0));
+            + FFMAX(extradata_size - (int)sizeof(ctx->cuparse_ext->raw_seqhdr_data), 0));
     if (!ctx->cuparse_ext) {
         ret = AVERROR(ENOMEM);
         goto error;
     }
 
+    if (extradata_size > 0)
+        memcpy(ctx->cuparse_ext->raw_seqhdr_data, extradata, extradata_size);
     ctx->cuparse_ext->format.seqhdr_data_length = extradata_size;
-    memcpy(ctx->cuparse_ext->raw_seqhdr_data, extradata, extradata_size);
 
     ctx->cuparseinfo.pExtVideoInfo = ctx->cuparse_ext;
 



More information about the ffmpeg-cvslog mailing list