Skip to content

Commit

Permalink
typefind/xdgmime: Validate mimetypes to be valid GstStructure names b…
Browse files Browse the repository at this point in the history
…efore using them

On macOS, for example, "text/*" can be returned as mimetype for
plaintext files but we don't allow '*' in structure names and this would
cause critical warnings.

It's a valid mimetype but not a valid structure name.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/616

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/877>
  • Loading branch information
sdroege authored and tp-m committed Oct 17, 2020
1 parent c7c870e commit 1484ab4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gst/typefind/gsttypefindfunctions.c
Expand Up @@ -5404,6 +5404,26 @@ vivo_type_find (GstTypeFind * tf, gpointer unused)
/*** XDG MIME typefinder (to avoid false positives mostly) ***/

#ifdef USE_GIO
static gboolean
xdgmime_validate_name (const gchar * name)
{
const gchar *s;

if (G_UNLIKELY (!g_ascii_isalpha (*name))) {
return FALSE;
}

/* FIXME: test name string more */
s = &name[1];
while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+", *s) != NULL))
s++;
if (G_UNLIKELY (*s != '\0')) {
return FALSE;
}

return TRUE;
}

static void
xdgmime_typefind (GstTypeFind * find, gpointer user_data)
{
Expand Down Expand Up @@ -5448,6 +5468,12 @@ xdgmime_typefind (GstTypeFind * find, gpointer user_data)
return;
}

if (!xdgmime_validate_name (mimetype)) {
GST_LOG ("Ignoring mimetype with invalid structure name");
g_free (mimetype);
return;
}

/* Again, we mainly want the xdg typefinding to prevent false-positives on
* non-media formats, so suggest the type with a probability that trumps
* uncertain results of our typefinders, but not more than that. */
Expand Down

0 comments on commit 1484ab4

Please sign in to comment.