gst/gstpad.c: Add sanity check to make sure we don't get smaller buffers than requested (and fallback to normal buffe...

Original commit message from CVS:
* gst/gstpad.c: (gst_pad_buffer_alloc_unchecked):
Add sanity check to make sure we don't get smaller buffers
than requested (and fallback to normal buffer alloc if we do).
This commit is contained in:
Tim-Philipp Müller 2008-05-19 11:59:34 +00:00
parent 092a80f2f0
commit fcc9f0b091
2 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2008-05-19 Tim-Philipp Müller <tim.muller at collabora co uk>
* gst/gstpad.c: (gst_pad_buffer_alloc_unchecked):
Add sanity check to make sure we don't get smaller buffers
than requested (and fallback to normal buffer alloc if we do).
2008-05-19 Wim Taymans <wim.taymans@collabora.co.uk> 2008-05-19 Wim Taymans <wim.taymans@collabora.co.uk>
* libs/gst/base/gstbasesink.c: (gst_base_sink_adjust_time), * libs/gst/base/gstbasesink.c: (gst_base_sink_adjust_time),

View file

@ -2671,12 +2671,18 @@ gst_pad_buffer_alloc_unchecked (GstPad * pad, guint64 offset, gint size,
goto fallback; goto fallback;
ret = bufferallocfunc (pad, offset, size, caps, buf); ret = bufferallocfunc (pad, offset, size, caps, buf);
if (G_UNLIKELY (ret != GST_FLOW_OK)) if (G_UNLIKELY (ret != GST_FLOW_OK))
goto error; goto error;
/* no error, but NULL buffer means fallback to the default */ /* no error, but NULL buffer means fallback to the default */
if (G_UNLIKELY (*buf == NULL)) if (G_UNLIKELY (*buf == NULL))
goto fallback; goto fallback;
/* sanity check */
if (G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
goto wrong_size;
/* If the buffer alloc function didn't set up the caps like it should, /* If the buffer alloc function didn't set up the caps like it should,
* do it for it */ * do it for it */
if (G_UNLIKELY (caps && (GST_BUFFER_CAPS (*buf) == NULL))) { if (G_UNLIKELY (caps && (GST_BUFFER_CAPS (*buf) == NULL))) {
@ -2699,6 +2705,14 @@ error:
"alloc function returned error (%d) %s", ret, gst_flow_get_name (ret)); "alloc function returned error (%d) %s", ret, gst_flow_get_name (ret));
return ret; return ret;
} }
wrong_size:
{
GST_CAT_ERROR_OBJECT (GST_CAT_PADS, pad, "buffer returned by alloc "
"function is too small: %u < %d", GST_BUFFER_SIZE (*buf), size);
gst_buffer_unref (*buf);
*buf = NULL;
goto fallback;
}
fallback: fallback:
{ {
/* fallback case, allocate a buffer of our own, add pad caps. */ /* fallback case, allocate a buffer of our own, add pad caps. */