discoverer: Make gst_discoverer_info_from_variant nullable

There is no guarantee that the passed in data is valid and we should return
NULL in that case.

Also add API safeguards

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8953>
This commit is contained in:
Thibault Saunier 2025-05-08 13:25:16 -04:00
parent fa44cfdaaa
commit 97fec43422
2 changed files with 13 additions and 4 deletions

View File

@ -807,7 +807,7 @@ the tags after the life-time of @info, you will need to copy them.</doc>
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c">Parses a #GVariant as produced by gst_discoverer_info_to_variant()
back to a #GstDiscovererInfo.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.h"/>
<return-value transfer-ownership="full">
<return-value transfer-ownership="full" nullable="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/pbutils/gstdiscoverer.c">A newly-allocated #GstDiscovererInfo.</doc>
<type name="DiscovererInfo" c:type="GstDiscovererInfo*"/>
</return-value>

View File

@ -2768,21 +2768,30 @@ gst_discoverer_info_to_variant (GstDiscovererInfo * info,
* Parses a #GVariant as produced by gst_discoverer_info_to_variant()
* back to a #GstDiscovererInfo.
*
* Returns: (transfer full): A newly-allocated #GstDiscovererInfo.
* Returns: (transfer full) (nullable): A newly-allocated #GstDiscovererInfo.
*
* Since: 1.6
*/
GstDiscovererInfo *
gst_discoverer_info_from_variant (GVariant * variant)
{
GstDiscovererInfo *info = g_object_new (GST_TYPE_DISCOVERER_INFO, NULL);
GVariant *info_variant = g_variant_get_variant (variant);
GVariant *info_specific_variant;
GVariant *wrapped;
g_return_val_if_fail (variant, NULL);
GVariant *info_variant = g_variant_get_variant (variant);
if (!info_variant) {
GST_WARNING ("Failed to get variant from serialized info");
return NULL;
}
GET_FROM_TUPLE (info_variant, variant, 0, &info_specific_variant);
GET_FROM_TUPLE (info_variant, variant, 1, &wrapped);
GstDiscovererInfo *info = g_object_new (GST_TYPE_DISCOVERER_INFO, NULL);
_parse_info (info, info_specific_variant);
_parse_discovery (wrapped, info);
g_variant_unref (info_specific_variant);