From 5168611f5564eb1d98ce3e9e0b0a855b6d067eef Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 23 Aug 2019 14:41:06 +0800 Subject: [PATCH] libs: surface: add pointer check for surface_new_from_formats. 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapisurface.c b/gst-libs/gst/vaapi/gstvaapisurface.c index d17b00e6c4..f092b549e5 100644 --- a/gst-libs/gst/vaapi/gstvaapisurface.c +++ b/gst-libs/gst/vaapi/gstvaapisurface.c @@ -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