]> git.sesse.net Git - ffmpeg/commitdiff
libavfilter/dnn/dnn_backend{openvino, tf}: check memory alloc non-NULL
authorChris Miceli <chris@miceli.net.au>
Wed, 14 Oct 2020 00:59:44 +0000 (11:59 +1100)
committerGuo, Yejun <yejun.guo@intel.com>
Wed, 14 Oct 2020 03:08:09 +0000 (11:08 +0800)
These previously would not check that the return value was non-null
meaning it was susceptible to a sigsegv. This checks those values.

libavfilter/dnn/dnn_backend_openvino.c
libavfilter/dnn/dnn_backend_tf.c

index 495225d0b3dadc21674d47414059bffef9626639..d510e162c6e636913a7038a6a4e82e62f729f0ce 100644 (file)
@@ -141,8 +141,20 @@ static DNNReturnType get_output_ov(void *model, const char *input_name, int inpu
 {
     DNNReturnType ret;
     OVModel *ov_model = (OVModel *)model;
+    OVContext *ctx = &ov_model->ctx;
     AVFrame *in_frame = av_frame_alloc();
-    AVFrame *out_frame = av_frame_alloc();
+    AVFrame *out_frame = NULL;
+
+    if (!in_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
+        return DNN_ERROR;
+    }
+    out_frame = av_frame_alloc();
+    if (!out_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
+        av_frame_free(&in_frame);
+        return DNN_ERROR;
+    }
     in_frame->width = input_width;
     in_frame->height = input_height;
 
index be860b11b57a0816ff8c39c076bed7095a0653dc..7923e1db694bcd08de4a0adf1d096b8b58bc76b8 100644 (file)
@@ -159,8 +159,22 @@ static DNNReturnType get_output_tf(void *model, const char *input_name, int inpu
 {
     DNNReturnType ret;
     TFModel *tf_model = (TFModel *)model;
+    TFContext *ctx = &tf_model->ctx;
     AVFrame *in_frame = av_frame_alloc();
-    AVFrame *out_frame = av_frame_alloc();
+    AVFrame *out_frame = NULL;
+
+    if (!in_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for input frame\n");
+        return DNN_ERROR;
+    }
+
+    out_frame = av_frame_alloc();
+    if (!out_frame) {
+        av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory for output frame\n");
+        av_frame_free(&in_frame);
+        return DNN_ERROR;
+    }
+
     in_frame->width = input_width;
     in_frame->height = input_height;