v4l2bufferpool: Validate stride/offset when importing
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 25 Jul 2018 23:27:01 +0000 (19:27 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 27 Aug 2018 17:41:30 +0000 (13:41 -0400)
This will prevent situation where buffer size allow importing but rendering
goes wrong due to a miss-match in expected stride and offset.

https://bugzilla.gnome.org/show_bug.cgi?id=583890

sys/v4l2/gstv4l2bufferpool.c

index 8c10f99..6e4ac1c 100644 (file)
@@ -742,10 +742,23 @@ gst_v4l2_buffer_pool_start (GstBufferPool * bpool)
 
   GST_DEBUG_OBJECT (pool, "activating pool");
 
-  if (pool->other_pool)
+  if (pool->other_pool) {
+    GstBuffer *buffer;
+
     if (!gst_buffer_pool_set_active (pool->other_pool, TRUE))
       goto other_pool_failed;
 
+    if (gst_buffer_pool_acquire_buffer (pool->other_pool, &buffer, NULL) !=
+        GST_FLOW_OK)
+      goto other_pool_failed;
+
+    if (!gst_v4l2_object_try_import (obj, buffer)) {
+      gst_buffer_unref (buffer);
+      goto cannot_import;
+    }
+    gst_buffer_unref (buffer);
+  }
+
   config = gst_buffer_pool_get_config (bpool);
   if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
           &max_buffers))
@@ -912,6 +925,11 @@ queue_failed:
     GST_ERROR_OBJECT (pool, "failed to queue buffers into the capture queue");
     return FALSE;
   }
+cannot_import:
+  {
+    GST_ERROR_OBJECT (pool, "cannot import buffers from downstream pool");
+    return FALSE;
+  }
 }
 
 static gboolean