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 691698 - Memory corruption: gst_pad_get_pad_template_caps returns a reference on GST_CAPS_ANY
Memory corruption: gst_pad_get_pad_template_caps returns a reference on GST_C...
Status: RESOLVED INVALID
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
1.0.5
Other Linux
: Normal major
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-14 08:57 UTC by Paul HENRYS
Modified: 2013-01-29 11:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (690 bytes, patch)
2013-01-14 08:58 UTC, Paul HENRYS
none Details | Review

Description Paul HENRYS 2013-01-14 08:57:33 UTC
Inside gst_pad_get_pad_template_caps function in gstpad.c, if the pad does not have a padtemplate it returns a reference on GST_CAPS_ANY that has been previously referenced with gst_caps_ref ().
The problem with this is that there is no shared access protection with a mutex for instance. gst_pad_get_pad_template_caps () is called in gst_pad_proxy_query_caps () which can be called by several threads and this might lead to memory corruption.
I think a new gstcaps of type ANY should be return using gst_caps_new_any (), see the patch in attachment.
Comment 1 Paul HENRYS 2013-01-14 08:58:30 UTC
Created attachment 233421 [details] [review]
Patch
Comment 2 Sebastian Dröge (slomo) 2013-01-14 09:18:52 UTC
GST_CAPS_ANY is initialized during gst_init() and never freed (so there's always at least one reference). gst_caps_ref() is increasing the refcount of that atomically and returning the new reference.

If you get any memory corruption, most likely some code is not handling refcounting on the caps correctly. Do you have a testcase to reproduce the memory corruption?
Comment 3 Paul HENRYS 2013-01-14 10:54:30 UTC
Thanks for your answer Sebastian. I agree with you but is there no risk to do like it's done right now because if several threads tried to ref or unref GST_CAPS_ANY that might lead to memory corruption. No?

Actually, the issue was coming from my own local code where GST_CAPS_ANY was used without referencing it and later on unref...

By the way, I would expect from elements to always have a padtemplate on their sink and src pads. In the description of input-selector there is a padtemplate for each sink and src pads but when asking for its src pad template caps with gst_pad_get_pad_template_caps () we can see there is no one and the function returns a new reference of GST_CAPS_ANY. I didn't check the code of input-selector but I'm wondering if it's normal.

So this bug is not from GStreamer if there is no risk of memory corruption as discussed in the first part of this comment. I apologize for disturbing :)
Comment 4 Sebastian Dröge (slomo) 2013-01-14 11:21:54 UTC
(In reply to comment #3)
> Thanks for your answer Sebastian. I agree with you but is there no risk to do
> like it's done right now because if several threads tried to ref or unref
> GST_CAPS_ANY that might lead to memory corruption. No?

No, gst_caps_ref() and all the ref()/unref() functions are threadsafe

> Actually, the issue was coming from my own local code where GST_CAPS_ANY was
> used without referencing it and later on unref...

GST_CAPS_ANY is unowned by the caller, you either have to call ref() on it or not call unref() on it later. You must call ref() on it if you intent to change it.

> By the way, I would expect from elements to always have a padtemplate on their
> sink and src pads. In the description of input-selector there is a padtemplate
> for each sink and src pads but when asking for its src pad template caps with
> gst_pad_get_pad_template_caps () we can see there is no one and the function
> returns a new reference of GST_CAPS_ANY. I didn't check the code of
> input-selector but I'm wondering if it's normal.

Yes, input-selector accepts ANY caps.