mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-27 09:36:53 +02:00
Merge branch '1729-mime-result-prio' into 'master'
Resolve "g_content_type_guess segfaults when passed an empty data buffer on Mac OS" Closes #1729 See merge request GNOME/glib!733
This commit is contained in:
commit
03ce878736
@ -39,7 +39,7 @@ test_guess (void)
|
|||||||
g_free (existing_directory);
|
g_free (existing_directory);
|
||||||
expected = g_content_type_from_mime_type ("inode/directory");
|
expected = g_content_type_from_mime_type ("inode/directory");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (uncertain);
|
g_assert_true (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ test_guess (void)
|
|||||||
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess ("foo.txt", data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("text/plain");
|
expected = g_content_type_from_mime_type ("text/plain");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
@ -61,21 +61,21 @@ test_guess (void)
|
|||||||
res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess ("foo", data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("text/plain");
|
expected = g_content_type_from_mime_type ("text/plain");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess ("foo.desktop", data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("application/x-desktop");
|
expected = g_content_type_from_mime_type ("application/x-desktop");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
|
res = g_content_type_guess (NULL, data, sizeof (data) - 1, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("application/x-desktop");
|
expected = g_content_type_from_mime_type ("application/x-desktop");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
@ -84,14 +84,14 @@ test_guess (void)
|
|||||||
res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
|
res = g_content_type_guess ("test.pot", (guchar *)"ABC abc", 7, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
|
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
|
res = g_content_type_guess ("test.pot", (guchar *)"msgid \"", 7, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
|
expected = g_content_type_from_mime_type ("text/x-gettext-translation-template");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ test_guess (void)
|
|||||||
res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
|
res = g_content_type_guess ("test.otf", (guchar *)"OTTO", 4, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("application/x-font-otf");
|
expected = g_content_type_from_mime_type ("application/x-font-otf");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
#endif
|
#endif
|
||||||
@ -115,7 +115,15 @@ test_guess (void)
|
|||||||
res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain);
|
res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 23, &uncertain);
|
||||||
expected = g_content_type_from_mime_type ("image/x-eps");
|
expected = g_content_type_from_mime_type ("image/x-eps");
|
||||||
g_assert_content_type_equals (expected, res);
|
g_assert_content_type_equals (expected, res);
|
||||||
g_assert (!uncertain);
|
g_assert_false (uncertain);
|
||||||
|
g_free (res);
|
||||||
|
g_free (expected);
|
||||||
|
|
||||||
|
/* The data below would be detected as a valid content type, but shouldn’t be read at all. */
|
||||||
|
res = g_content_type_guess (NULL, (guchar *)"%!PS-Adobe-2.0 EPSF-1.2", 0, &uncertain);
|
||||||
|
expected = g_content_type_from_mime_type ("application/x-zerosize");
|
||||||
|
g_assert_content_type_equals (expected, res);
|
||||||
|
g_assert_false (uncertain);
|
||||||
g_free (res);
|
g_free (res);
|
||||||
g_free (expected);
|
g_free (expected);
|
||||||
}
|
}
|
||||||
@ -127,7 +135,7 @@ test_unknown (void)
|
|||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
unknown = g_content_type_from_mime_type ("application/octet-stream");
|
unknown = g_content_type_from_mime_type ("application/octet-stream");
|
||||||
g_assert (g_content_type_is_unknown (unknown));
|
g_assert_true (g_content_type_is_unknown (unknown));
|
||||||
str = g_content_type_get_mime_type (unknown);
|
str = g_content_type_get_mime_type (unknown);
|
||||||
g_assert_cmpstr (str, ==, "application/octet-stream");
|
g_assert_cmpstr (str, ==, "application/octet-stream");
|
||||||
g_free (str);
|
g_free (str);
|
||||||
@ -143,8 +151,8 @@ test_subtype (void)
|
|||||||
plain = g_content_type_from_mime_type ("text/plain");
|
plain = g_content_type_from_mime_type ("text/plain");
|
||||||
xml = g_content_type_from_mime_type ("application/xml");
|
xml = g_content_type_from_mime_type ("application/xml");
|
||||||
|
|
||||||
g_assert (g_content_type_is_a (xml, plain));
|
g_assert_true (g_content_type_is_a (xml, plain));
|
||||||
g_assert (g_content_type_is_mime_type (xml, "text/plain"));
|
g_assert_true (g_content_type_is_mime_type (xml, "text/plain"));
|
||||||
|
|
||||||
g_free (plain);
|
g_free (plain);
|
||||||
g_free (xml);
|
g_free (xml);
|
||||||
@ -175,11 +183,11 @@ test_list (void)
|
|||||||
|
|
||||||
types = g_content_types_get_registered ();
|
types = g_content_types_get_registered ();
|
||||||
|
|
||||||
g_assert (g_list_length (types) > 1);
|
g_assert_cmpuint (g_list_length (types), >, 1);
|
||||||
|
|
||||||
/* just check that some types are in the list */
|
/* just check that some types are in the list */
|
||||||
g_assert (g_list_find_custom (types, plain, find_mime) != NULL);
|
g_assert_nonnull (g_list_find_custom (types, plain, find_mime));
|
||||||
g_assert (g_list_find_custom (types, xml, find_mime) != NULL);
|
g_assert_nonnull (g_list_find_custom (types, xml, find_mime));
|
||||||
|
|
||||||
g_list_free_full (types, g_free);
|
g_list_free_full (types, g_free);
|
||||||
|
|
||||||
@ -193,15 +201,15 @@ test_executable (void)
|
|||||||
gchar *type;
|
gchar *type;
|
||||||
|
|
||||||
type = g_content_type_from_mime_type ("application/x-executable");
|
type = g_content_type_from_mime_type ("application/x-executable");
|
||||||
g_assert (g_content_type_can_be_executable (type));
|
g_assert_true (g_content_type_can_be_executable (type));
|
||||||
g_free (type);
|
g_free (type);
|
||||||
|
|
||||||
type = g_content_type_from_mime_type ("text/plain");
|
type = g_content_type_from_mime_type ("text/plain");
|
||||||
g_assert (g_content_type_can_be_executable (type));
|
g_assert_true (g_content_type_can_be_executable (type));
|
||||||
g_free (type);
|
g_free (type);
|
||||||
|
|
||||||
type = g_content_type_from_mime_type ("image/png");
|
type = g_content_type_from_mime_type ("image/png");
|
||||||
g_assert (!g_content_type_can_be_executable (type));
|
g_assert_false (g_content_type_can_be_executable (type));
|
||||||
g_free (type);
|
g_free (type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +221,7 @@ test_description (void)
|
|||||||
|
|
||||||
type = g_content_type_from_mime_type ("text/plain");
|
type = g_content_type_from_mime_type ("text/plain");
|
||||||
desc = g_content_type_get_description (type);
|
desc = g_content_type_get_description (type);
|
||||||
g_assert (desc != NULL);
|
g_assert_nonnull (desc);
|
||||||
|
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
g_free (type);
|
g_free (type);
|
||||||
@ -227,17 +235,17 @@ test_icon (void)
|
|||||||
|
|
||||||
type = g_content_type_from_mime_type ("text/plain");
|
type = g_content_type_from_mime_type ("text/plain");
|
||||||
icon = g_content_type_get_icon (type);
|
icon = g_content_type_get_icon (type);
|
||||||
g_assert (G_IS_ICON (icon));
|
g_assert_true (G_IS_ICON (icon));
|
||||||
if (G_IS_THEMED_ICON (icon))
|
if (G_IS_THEMED_ICON (icon))
|
||||||
{
|
{
|
||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
g_assert (g_strv_contains (names, "text-*"));
|
g_assert_true (g_strv_contains (names, "text-*"));
|
||||||
#else
|
#else
|
||||||
g_assert (g_strv_contains (names, "text-plain"));
|
g_assert_true (g_strv_contains (names, "text-plain"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic"));
|
g_assert_true (g_strv_contains (names, "text-x-generic"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
@ -245,15 +253,15 @@ test_icon (void)
|
|||||||
|
|
||||||
type = g_content_type_from_mime_type ("application/rtf");
|
type = g_content_type_from_mime_type ("application/rtf");
|
||||||
icon = g_content_type_get_icon (type);
|
icon = g_content_type_get_icon (type);
|
||||||
g_assert (G_IS_ICON (icon));
|
g_assert_true (G_IS_ICON (icon));
|
||||||
if (G_IS_THEMED_ICON (icon))
|
if (G_IS_THEMED_ICON (icon))
|
||||||
{
|
{
|
||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
g_assert (g_strv_contains (names, "application-rtf"));
|
g_assert_true (g_strv_contains (names, "application-rtf"));
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
g_assert (g_strv_contains (names, "x-office-document"));
|
g_assert_true (g_strv_contains (names, "x-office-document"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
@ -269,20 +277,20 @@ test_symbolic_icon (void)
|
|||||||
|
|
||||||
type = g_content_type_from_mime_type ("text/plain");
|
type = g_content_type_from_mime_type ("text/plain");
|
||||||
icon = g_content_type_get_symbolic_icon (type);
|
icon = g_content_type_get_symbolic_icon (type);
|
||||||
g_assert (G_IS_ICON (icon));
|
g_assert_true (G_IS_ICON (icon));
|
||||||
if (G_IS_THEMED_ICON (icon))
|
if (G_IS_THEMED_ICON (icon))
|
||||||
{
|
{
|
||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
g_assert (g_strv_contains (names, "text-*-symbolic"));
|
g_assert_true (g_strv_contains (names, "text-*-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "text-*"));
|
g_assert_true (g_strv_contains (names, "text-*"));
|
||||||
#else
|
#else
|
||||||
g_assert (g_strv_contains (names, "text-plain-symbolic"));
|
g_assert_true (g_strv_contains (names, "text-plain-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic-symbolic"));
|
g_assert_true (g_strv_contains (names, "text-x-generic-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "text-plain"));
|
g_assert_true (g_strv_contains (names, "text-plain"));
|
||||||
g_assert (g_strv_contains (names, "text-x-generic"));
|
g_assert_true (g_strv_contains (names, "text-x-generic"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
@ -290,17 +298,17 @@ test_symbolic_icon (void)
|
|||||||
|
|
||||||
type = g_content_type_from_mime_type ("application/rtf");
|
type = g_content_type_from_mime_type ("application/rtf");
|
||||||
icon = g_content_type_get_symbolic_icon (type);
|
icon = g_content_type_get_symbolic_icon (type);
|
||||||
g_assert (G_IS_ICON (icon));
|
g_assert_true (G_IS_ICON (icon));
|
||||||
if (G_IS_THEMED_ICON (icon))
|
if (G_IS_THEMED_ICON (icon))
|
||||||
{
|
{
|
||||||
const gchar *const *names;
|
const gchar *const *names;
|
||||||
|
|
||||||
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
names = g_themed_icon_get_names (G_THEMED_ICON (icon));
|
||||||
g_assert (g_strv_contains (names, "application-rtf-symbolic"));
|
g_assert_true (g_strv_contains (names, "application-rtf-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "application-rtf"));
|
g_assert_true (g_strv_contains (names, "application-rtf"));
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
g_assert (g_strv_contains (names, "x-office-document-symbolic"));
|
g_assert_true (g_strv_contains (names, "x-office-document-symbolic"));
|
||||||
g_assert (g_strv_contains (names, "x-office-document"));
|
g_assert_true (g_strv_contains (names, "x-office-document"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
|
@ -531,6 +531,7 @@ xdg_mime_get_mime_type_for_data (const void *data,
|
|||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
|
if (result_prio != NULL)
|
||||||
*result_prio = 100;
|
*result_prio = 100;
|
||||||
return XDG_MIME_TYPE_EMPTY;
|
return XDG_MIME_TYPE_EMPTY;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user