Commit db3d2f35 authored by Nicolas Dufresne's avatar Nicolas Dufresne

v4l2bufferpool: Early catch short allocation

Catch short allocation after saving the format. This is not a catch all, but should catch
most of the miss-behaving drivers when doing S_FMT/G_FMT and avoid potential crash.
parent 2b0ac06a
...@@ -2623,6 +2623,9 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps) ...@@ -2623,6 +2623,9 @@ gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps)
done: done:
gst_v4l2_object_save_format (v4l2object, fmtdesc, &format, &info, &align); gst_v4l2_object_save_format (v4l2object, fmtdesc, &format, &info, &align);
if (v4l2object->sizeimage < GST_VIDEO_INFO_SIZE (&info))
goto short_allocation;
/* now configure the pool */ /* now configure the pool */
if (!gst_v4l2_object_setup_pool (v4l2object, caps)) if (!gst_v4l2_object_setup_pool (v4l2object, caps))
goto pool_failed; goto pool_failed;
...@@ -2707,6 +2710,14 @@ set_parm_failed: ...@@ -2707,6 +2710,14 @@ set_parm_failed:
GST_ERROR_SYSTEM); GST_ERROR_SYSTEM);
goto done; goto done;
} }
short_allocation:
{
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
(_("Video device provided a image size that is too short.")),
("Expected at least %" G_GSIZE_FORMAT " but got %u", info.size,
v4l2object->sizeimage));
return FALSE;
}
pool_failed: pool_failed:
{ {
/* setup_pool already send the error */ /* setup_pool already send the error */
...@@ -2789,6 +2800,9 @@ gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info) ...@@ -2789,6 +2800,9 @@ gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object, GstVideoInfo * info)
gst_v4l2_object_save_format (v4l2object, fmtdesc, &fmt, info, &align); gst_v4l2_object_save_format (v4l2object, fmtdesc, &fmt, info, &align);
if (v4l2object->sizeimage < GST_VIDEO_INFO_SIZE (info))
goto short_allocation;
/* Shall we setup the pool ? */ /* Shall we setup the pool ? */
return TRUE; return TRUE;
...@@ -2822,6 +2836,14 @@ unsupported_format: ...@@ -2822,6 +2836,14 @@ unsupported_format:
GST_FOURCC_ARGS (fmt.fmt.pix.pixelformat))); GST_FOURCC_ARGS (fmt.fmt.pix.pixelformat)));
return FALSE; return FALSE;
} }
short_allocation:
{
GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,
(_("Video device provided a image size that is too short.")),
("Expected at least %" G_GSIZE_FORMAT " but got %u", info->size,
v4l2object->sizeimage));
return FALSE;
}
} }
gboolean gboolean
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment