msdk: Fix unchecked return values
authorMengkejiergeli Ba <mengkejiergeli.ba@intel.com>
Thu, 17 Feb 2022 07:12:52 +0000 (15:12 +0800)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 25 Feb 2022 02:04:20 +0000 (02:04 +0000)
There are several calls of gst_video_info_from_caps and gst_video_frame_copy
without checks for the returned values. This patch adds all necessary
function return checks.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1738>

subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c
subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c

index 748ab1f..58aef3d 100644 (file)
@@ -882,7 +882,12 @@ gst_msdkdec_finish_task (GstMsdkDec * thiz, MsdkDecTask * task)
         GST_MINI_OBJECT_FLAG_SET (surface->buf, GST_MINI_OBJECT_FLAG_LOCKABLE);
         frame->output_buffer = gst_buffer_ref (surface->buf);
       } else {
-        gst_video_frame_copy (&surface->copy, &surface->data);
+        if (!gst_video_frame_copy (&surface->copy, &surface->data)) {
+          GST_ERROR_OBJECT (thiz, "Failed to copy surface data");
+          gst_video_frame_unmap (&surface->copy);
+          gst_video_frame_unmap (&surface->data);
+          return GST_FLOW_ERROR;
+        }
         frame->output_buffer = gst_buffer_ref (surface->copy.buffer);
         unmap_frame (thiz, surface);
       }
@@ -1321,7 +1326,12 @@ gst_msdkdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
           gst_video_decoder_get_output_state (GST_VIDEO_DECODER (thiz));
       if (output_state) {
         if (output_state->allocation_caps) {
-          gst_video_info_from_caps (&alloc_info, output_state->allocation_caps);
+          if (!gst_video_info_from_caps (&alloc_info,
+                  output_state->allocation_caps)) {
+            GST_ERROR_OBJECT (thiz, "Failed to get video info from caps");
+            flow = GST_FLOW_ERROR;
+            goto error;
+          }
 
           /* Check whether we need complete reset for dynamic resolution change */
           if (thiz->param.mfx.FrameInfo.Width >
@@ -1727,7 +1737,10 @@ gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
         min_buffers, max_buffers);
     if (!gst_buffer_pool_set_config (pool, pool_config))
       goto error_set_config;
-    gst_video_info_from_caps (&thiz->non_msdk_pool_info, pool_caps);
+    if (!gst_video_info_from_caps (&thiz->non_msdk_pool_info, pool_caps)) {
+      GST_ERROR_OBJECT (thiz, "Failed to get video info from caps");
+      return FALSE;
+    }
 
     /* update width and height with actual negotiated values */
     output_state =
index 3bdc982..b409c2e 100644 (file)
@@ -1300,8 +1300,10 @@ gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
           gst_caps_get_features (out_caps, 0)))
     thiz->need_vpp = 1;
 
-  gst_video_info_from_caps (&in_info, caps);
-  gst_video_info_from_caps (&out_info, out_caps);
+  if (!gst_video_info_from_caps (&in_info, caps))
+    goto error_no_video_info;
+  if (!gst_video_info_from_caps (&out_info, out_caps))
+    goto error_no_video_info;
 
   if (!gst_video_info_is_equal (&in_info, &thiz->sinkpad_info))
     sinkpad_info_changed = TRUE;
@@ -1347,6 +1349,10 @@ gst_msdkvpp_set_caps (GstBaseTransform * trans, GstCaps * caps,
   }
 
   return TRUE;
+
+error_no_video_info:
+  GST_ERROR_OBJECT (thiz, "Failed to get video info from caps");
+  return FALSE;
 }
 
 static gboolean