From 3036521fb6f0f6fc86e5c893837d936e2675e58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 17 Oct 2020 10:42:49 +0300 Subject: [PATCH] typefind/xdgmime: Validate mimetypes to be valid GstStructure names before 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: --- gst/typefind/gsttypefindfunctions.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index cbb0312c9e..3ef051c56b 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -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) { @@ -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. */