summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2021-08-09 16:53:52 +0200
committerMichael Catanzaro <mcatanzaro@gnome.org>2021-08-12 19:19:58 +0000
commit8cc38c8a6ab9d08e5db595efd2fff10357f97ddb (patch)
tree3818817d79265b2a2394b30cb90a930fd7cd4e3d
parent12520678cf546e9347b34c83f509f9c1a5f10c39 (diff)
downloadepiphany-8cc38c8a6ab9d08e5db595efd2fff10357f97ddb.tar.gz
Always check filter content type
Try to handle misconfigured servers and check the file content locally based on content. If it is not valid, remove stray file. Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1543 Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/998> (cherry picked from commit 1736e9ed3933204701dc0b022252667520bb0ea1)
-rw-r--r--embed/ephy-filters-manager.c73
1 files changed, 62 insertions, 11 deletions
diff --git a/embed/ephy-filters-manager.c b/embed/ephy-filters-manager.c
index 14bd549e7..48693de71 100644
--- a/embed/ephy-filters-manager.c
+++ b/embed/ephy-filters-manager.c
@@ -571,9 +571,59 @@ filter_info_setup_load_file (FilterInfo *self,
}
static void
+json_file_deleted (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+ if (!g_file_delete_finish (G_FILE (source), res, &error))
+ g_warning ("Could not delete filter json file: %s", error->message);
+}
+
+typedef struct {
+ EphyDownload *download;
+ FilterInfo *self;
+} FilterJsonInfoAsyncData;
+
+static void
+json_file_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+ FilterJsonInfoAsyncData *data = user_data;
+ GFile *json_file = G_FILE (source_object);
+ g_autoptr (GFileInfo) info = g_file_query_info_finish (json_file, res, &error);
+ const char *content_type = NULL;
+
+ if (info)
+ content_type = g_file_info_get_content_type (info);
+ else
+ g_warning ("Couldn't query filter file %s: %s", ephy_download_get_destination_uri (data->download), error->message);
+
+ if (content_type && g_strcmp0 ("application/json", content_type) == 0) {
+ filter_info_setup_load_file (data->self, json_file);
+ } else {
+ g_warning ("Filter source %s has invalid MIME type: %s",
+ ephy_download_get_destination_uri (data->download),
+ content_type);
+
+ g_file_delete_async (json_file, G_PRIORITY_DEFAULT, NULL, json_file_deleted, NULL);
+
+ filter_info_setup_done (data->self);
+ }
+
+ g_object_unref (data->download);
+ g_free (data);
+}
+
+static void
download_completed_cb (EphyDownload *download,
FilterInfo *self)
{
+ g_autoptr (GFile) json_file = NULL;
+ FilterJsonInfoAsyncData *data = NULL;
+
g_assert (download);
g_assert (self);
@@ -581,17 +631,18 @@ download_completed_cb (EphyDownload *download,
LOG ("Filter source %s fetched from <%s>", filter_info_get_identifier (self), self->source_uri);
- if (g_strcmp0 ("application/json", ephy_download_get_content_type (download)) == 0) {
- g_autoptr (GFile) json_file = g_file_new_for_uri (ephy_download_get_destination_uri (download));
- filter_info_setup_load_file (self, json_file);
- } else {
- g_warning ("Filter source %s has invalid MIME type: %s",
- ephy_download_get_destination_uri (download),
- ephy_download_get_content_type (download));
- filter_info_setup_done (self);
- }
-
- g_object_unref (download);
+ data = g_new0 (FilterJsonInfoAsyncData, 1);
+ data->download = download;
+ data->self = self;
+
+ json_file = g_file_new_for_uri (ephy_download_get_destination_uri (download));
+ g_file_query_info_async (json_file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ json_file_info_callback,
+ data);
}
static void