gst-libs/gst/netbuffer/gstnetbuffer.c: Fix copying of GstNetBuffer (would crash before, or at least lead to invalid m...

Original commit message from CVS:
* gst-libs/gst/netbuffer/gstnetbuffer.c:
(notgst_buffer_copy_fields_in_place), (gst_netbuffer_copy):
Fix copying of GstNetBuffer (would crash before, or at least lead to
invalid memory access, #410772), for now by copying the GstBuffer copy
code from the core over here so we can copy the GstBuffer fields on a
provided buffer instance (of type GstNetBuffer in this case). Would be
better to fix this with some support by the core though (and in the long
run change the broken GstBuffer/GstMiniObject copy semantics, #393099).
* tests/check/Makefile.am:
Enable unit test for GstNetBuffer.
This commit is contained in:
Tim-Philipp Müller 2007-02-22 12:57:47 +00:00
parent d9b6796d91
commit 011471dbbb
3 changed files with 57 additions and 4 deletions

View file

@ -1,3 +1,17 @@
2007-02-22 Tim-Philipp Müller <tim at centricular dot net>
* gst-libs/gst/netbuffer/gstnetbuffer.c:
(notgst_buffer_copy_fields_in_place), (gst_netbuffer_copy):
Fix copying of GstNetBuffer (would crash before, or at least lead to
invalid memory access, #410772), for now by copying the GstBuffer copy
code from the core over here so we can copy the GstBuffer fields on a
provided buffer instance (of type GstNetBuffer in this case). Would be
better to fix this with some support by the core though (and in the long
run change the broken GstBuffer/GstMiniObject copy semantics, #393099).
* tests/check/Makefile.am:
Enable unit test for GstNetBuffer.
2007-02-22 Andy Wingo <wingo@pobox.com>
* gst-libs/gst/audio/gstbaseaudiosink.c

View file

@ -88,14 +88,52 @@ gst_netbuffer_finalize (GstNetBuffer * nbuf)
GST_MINI_OBJECT_CLASS (parent_class)->finalize (GST_MINI_OBJECT (nbuf));
}
/* this is copy'n'pasted from _gst_buffer_copy() in lack of a better solution;
* keep in sync with _gst_buffer_copy() */
static void
notgst_buffer_copy_fields_in_place (GstBuffer * copy, GstBuffer * buffer)
{
guint mask;
GST_LOG ("copying %p to %p", buffer, copy);
/* copy relevant flags */
mask = GST_BUFFER_FLAG_PREROLL | GST_BUFFER_FLAG_IN_CAPS |
GST_BUFFER_FLAG_DELTA_UNIT | GST_BUFFER_FLAG_DISCONT |
GST_BUFFER_FLAG_GAP;
GST_MINI_OBJECT_FLAGS (copy) |= GST_MINI_OBJECT_FLAGS (buffer) & mask;
/* we simply copy everything from our parent */
copy->data = g_memdup (buffer->data, buffer->size);
/* make sure it gets freed (even if the parent is subclassed, we return a
normal buffer) */
copy->malloc_data = copy->data;
copy->size = buffer->size;
GST_BUFFER_TIMESTAMP (copy) = GST_BUFFER_TIMESTAMP (buffer);
GST_BUFFER_DURATION (copy) = GST_BUFFER_DURATION (buffer);
GST_BUFFER_OFFSET (copy) = GST_BUFFER_OFFSET (buffer);
GST_BUFFER_OFFSET_END (copy) = GST_BUFFER_OFFSET_END (buffer);
if (GST_BUFFER_CAPS (buffer))
GST_BUFFER_CAPS (copy) = gst_caps_ref (GST_BUFFER_CAPS (buffer));
else
GST_BUFFER_CAPS (copy) = NULL;
}
static GstNetBuffer *
gst_netbuffer_copy (GstNetBuffer * nbuf)
{
GstNetBuffer *copy;
copy =
(GstNetBuffer *) GST_MINI_OBJECT_CLASS (parent_class)->
copy (GST_MINI_OBJECT (nbuf));
copy = gst_netbuffer_new ();
/* can't just chain up to parent_class::copy() because that will allocate
* a normal GstBuffer for us, so we'd lose the to/from fields and we don't
* want that */
notgst_buffer_copy_fields_in_place (GST_BUFFER_CAST (copy),
GST_BUFFER_CAST (nbuf));
memcpy (&copy->to, &nbuf->to, sizeof (nbuf->to));
memcpy (&copy->from, &nbuf->from, sizeof (nbuf->from));

View file

@ -77,6 +77,7 @@ check_PROGRAMS = \
gst/typefindfunctions \
libs/audio \
libs/cddabasesrc \
libs/netbuffer \
libs/tag \
libs/video \
libs/utils \
@ -94,7 +95,7 @@ VALGRIND_TO_FIX = \
libs/video
# these tests don't even pass
noinst_PROGRAMS = libs/netbuffer
noinst_PROGRAMS =
AM_CFLAGS = $(GST_CFLAGS) $(GST_CHECK_CFLAGS)
LDADD = $(GST_LIBS) $(GST_CHECK_LIBS)