After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 665989 - a52dec: segfault when copying liba52's buffer into gst's buffer
a52dec: segfault when copying liba52's buffer into gst's buffer
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-ugly
git master
Other All
: Normal blocker
: 0.10.20
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2011-12-12 09:57 UTC by Julien Isorce
Modified: 2012-01-18 15:30 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to avoid segfault when filling in gst buffer (4.86 KB, patch)
2011-12-12 09:57 UTC, Julien Isorce
committed Details | Review

Description Julien Isorce 2011-12-12 09:57:16 UTC
Created attachment 203240 [details] [review]
patch to avoid segfault when filling in gst buffer

Segfault may happen when doing:

((sample_t *) GST_BUFFER_DATA (buf))[n * chans + c] = samples[c * 256 + n];
Comment 1 Tim-Philipp Müller 2011-12-12 10:30:25 UTC
Looks to me like there's a bug somewhere else downstream, maybe in the audiosink?

If the gst_pad_alloc_buffer() returned GST_FLOW_OK the buffer should be of the size requested, I think. And in the case that such a check would actually be necessary, we would probably want to check for the right size then rather than just for >0.
Comment 2 Mark Nauwelaerts 2011-12-12 10:42:14 UTC
I would also have expected such gst_pad_alloc_buffer() behaviour, but recently came across bug #635461 where it appears this need not always be so (in some not very clear unusual circumstances).
Comment 3 Sebastian Dröge (slomo) 2011-12-12 12:35:20 UTC
The buffer returned by gst_pad_alloc_buffer() has to be checked by the caller. It could be of different size or with different caps than requested and the caller must handle this. This is not very convient but that's how it is in 0.10

Different caps or sizes can happen for example if a capsfilter changes the caps
Comment 4 Mark Nauwelaerts 2011-12-12 12:42:11 UTC
And what about the _and_set_caps variant ?  AFAICS, core does some additional stuff like configuring the src caps which would probably not allow for changing caps for an element with fixed src pad caps.

Though that still seems to leave the case where new (but equal) caps are provided with a smaller size.
Comment 5 Sebastian Dröge (slomo) 2011-12-12 12:57:28 UTC
The only difference of the _set_caps() variant is, that it automatically calls your srcpad's setcaps function. core doesn't do anything special for the non-set_caps() variant other than giving you the buffer provided by downstream.


Also downstream is not required to check if the different caps it returns (and in the case of capsfilter the size will be 0 btw, capsfilter can't calculate the size of buffers from the caps) are actually supported by upstream. Upstream always has to check the caps and size.
Comment 6 Mark Nauwelaerts 2011-12-12 13:07:24 UTC
(In reply to comment #5)
> The only difference of the _set_caps() variant is, that it automatically calls
> your srcpad's setcaps function. core doesn't do anything special for the
> non-set_caps() variant other than giving you the buffer provided by downstream.
> 

... but only after calling gst_pad_accept_caps(), which should not succeed in a typical fixed src caps situation (for really different caps at least).

> 
> Also downstream is not required to check if the different caps it returns (and
> in the case of capsfilter the size will be 0 btw, capsfilter can't calculate
> the size of buffers from the caps) are actually supported by upstream. Upstream
> always has to check the caps and size.

Yes, upstream should check, but that could be core code, as in:

(from gst_pad_alloc_buffer_full())
  /* sanity check (only if caps are the same) */
  if (G_LIKELY (newcaps == caps) && G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
    goto wrong_size_fallback;

In another world, it could/might always check regardless of whether caps are the same.
Comment 7 Sebastian Dröge (slomo) 2011-12-12 13:24:09 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > The only difference of the _set_caps() variant is, that it automatically calls
> > your srcpad's setcaps function. core doesn't do anything special for the
> > non-set_caps() variant other than giving you the buffer provided by downstream.
> > 
> 
> ... but only after calling gst_pad_accept_caps(), which should not succeed in a
> typical fixed src caps situation (for really different caps at least).

Yes, if the _set_caps() variant is used that's true. If it isn't the caller has to do this.

> > 
> > Also downstream is not required to check if the different caps it returns (and
> > in the case of capsfilter the size will be 0 btw, capsfilter can't calculate
> > the size of buffers from the caps) are actually supported by upstream. Upstream
> > always has to check the caps and size.
> 
> Yes, upstream should check, but that could be core code, as in:
> 
> (from gst_pad_alloc_buffer_full())
>   /* sanity check (only if caps are the same) */
>   if (G_LIKELY (newcaps == caps) && G_UNLIKELY (GST_BUFFER_SIZE (*buf) < size))
>     goto wrong_size_fallback;
> 
> In another world, it could/might always check regardless of whether caps are
> the same.

Agreed, fortunately this is gone in 0.11 and replaced by something better ;)
Comment 8 Sebastian Dröge (slomo) 2011-12-13 13:55:39 UTC
Comment on attachment 203240 [details] [review]
patch to avoid segfault when filling in gst buffer

Partially committed (the state check)
Comment 9 Sebastian Dröge (slomo) 2011-12-13 13:55:59 UTC
commit 220b88fcc1ce0e203cc042a4dffef381a87bda1c
Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
Date:   Tue Dec 13 14:54:18 2011 +0100

    a52dec: Don't claim to support upstream renegotiation
    
    and use fixed caps on the srcpad. To correctly support
    upstream renegotiation a52dec would need to check if the
    caps of the downstream allocated buffer are the requested
    caps or if the size is different.
    
    Fixes bug #665989.

commit cdf8d0f6b2d784cf7cce360a310cef3adebc3d66
Author: Julien Isorce <julien.isorce@gmail.com>
Date:   Tue Dec 13 14:52:26 2011 +0100

    a52dec: Check that the a52_state is correctly initialized
Comment 10 Sebastian Dröge (slomo) 2011-12-14 13:58:48 UTC
This is not entirely fixed, see bug #666174
Comment 11 Julien Isorce 2011-12-20 14:00:32 UTC
I cannot reproduce the problem since bug #666174 has been fixed (both before and after been ported to GstAudioEncoder)