Bug 1427700 - Don't return valid HandlerApp for the application/octet-stream content type; r?stransky draft
authorJan Horak <jhorak@redhat.com>
Thu, 17 May 2018 17:02:56 +0200
changeset 796338 44707daeb1a83bcc9c11d1b05d76c4a96fab2a03
parent 795256 cf3ee14023483cbbb57129479537c713e22c1980
push id110221
push userbmo:jhorak@redhat.com
push dateThu, 17 May 2018 15:03:30 +0000
reviewersstransky
bugs1427700
milestone62.0a1
Bug 1427700 - Don't return valid HandlerApp for the application/octet-stream content type; r?stransky When server set Content-type:application/octet-stream to the file there is a chance on some Linux distros that "unknown" file handler is selected to open the file which leads to strange list of application handlers. The logic leads to nsOSHelperAppService::GetFromType where the nsGNOMERegistry::GetFromType is called which could return useless "unknown" handler app. MozReview-Commit-ID: 5RgviXEBUmj
toolkit/system/gnome/nsGIOService.cpp
--- a/toolkit/system/gnome/nsGIOService.cpp
+++ b/toolkit/system/gnome/nsGIOService.cpp
@@ -521,16 +521,22 @@ nsGIOService::GetAppForMimeType(const ns
     return NS_OK;
   }
 
   char *content_type =
     g_content_type_from_mime_type(PromiseFlatCString(aMimeType).get());
   if (!content_type)
     return NS_ERROR_FAILURE;
 
+  // GIO returns "unknown" appinfo for the application/octet-stream, which is
+  // useless. It's better to fallback to create appinfo from file extension later.
+  if (g_content_type_is_unknown(content_type)) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   GAppInfo *app_info = g_app_info_get_default_for_type(content_type, false);
   if (app_info) {
     nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info);
     NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY);
     NS_ADDREF(*aApp = mozApp);
   } else {
     g_free(content_type);
     return NS_ERROR_FAILURE;