libs: surface: add pointer check for surface_new_from_formats.
authorHe Junyan <junyan.he@hotmail.com>
Fri, 23 Aug 2019 06:41:06 +0000 (14:41 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 10 Sep 2019 12:32:58 +0000 (12:32 +0000)
The command line:
  gst-launch-1.0 filesrc location=some_name.mjpeg ! jpegparse !
  vaapijpegdec !  videoconvert ! video/x-raw,format=I420 ! vaapisink
will crash on i965 driver because of no pointer check.

We now generate the video format map between GST format and VA format
dynamically based on the image format returned by vaQueryImageFormats.
i965 driver does to report image format of 444P and Y800 forcc, while
the jpeg decoder context VASurfaceAttribPixelFormat use them. We can
not recognize these format and pass a NULL pointer to
gst_vaapi_surface_new_from_formats.
We need to add a pointer check here and let the fallback logic handle
this case correctly.
Other drivers work well.

gst-libs/gst/vaapi/gstvaapisurface.c

index d17b00e..f092b54 100644 (file)
@@ -327,10 +327,12 @@ gst_vaapi_surface_new_from_formats (GstVaapiDisplay * display,
   GstVaapiSurface *surface;
   guint i;
 
-  for (i = 0; i < formats->len; i++) {
-    GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
-    if (format == gst_vaapi_video_format_from_chroma (chroma_type))
-      return gst_vaapi_surface_new (display, chroma_type, width, height);
+  if (formats) {
+    for (i = 0; i < formats->len; i++) {
+      GstVideoFormat format = g_array_index (formats, GstVideoFormat, i);
+      if (format == gst_vaapi_video_format_from_chroma (chroma_type))
+        return gst_vaapi_surface_new (display, chroma_type, width, height);
+    }
   }
 
   /* Fallback: if there's no format valid for the chroma type let's