[gnome-software] Use a hashed URL prefix for the screenshot local cache filename



commit ec41a3671850df63dabe04f197f638956af2ddba
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 2 09:38:18 2016 +0000

    Use a hashed URL prefix for the screenshot local cache filename
    
    For metadata that has not been run with 'appstream-util mirror-screenshots' all
    it takes is for one upstream to choose the same basename for the URL as another
    application before there is a clash, for instance 'Screenshot1.png'.
    
    This scheme should also stop evil apps showing the wrong screenshot for other
    applications.
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=761434

 src/gs-screenshot-image.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-screenshot-image.c b/src/gs-screenshot-image.c
index 7f9c8a9..7c015b1 100644
--- a/src/gs-screenshot-image.c
+++ b/src/gs-screenshot-image.c
@@ -336,6 +336,19 @@ gs_screenshot_image_set_use_desktop_background (GsScreenshotImage *ssimg,
 }
 
 /**
+ * gs_screenshot_get_cachefn_for_url:
+ **/
+static gchar *
+gs_screenshot_get_cachefn_for_url (const gchar *url)
+{
+       g_autofree gchar *basename = NULL;
+       g_autofree gchar *checksum = NULL;
+       checksum = g_compute_checksum_for_string (G_CHECKSUM_SHA256, url, -1);
+       basename = g_path_get_basename (url);
+       return g_strdup_printf ("%s-%s", checksum, basename);
+}
+
+/**
  * gs_screenshot_image_load_async:
  **/
 void
@@ -377,7 +390,7 @@ gs_screenshot_image_load_async (GsScreenshotImage *ssimg,
                return;
        }
        url = as_image_get_url (im);
-       basename = g_path_get_basename (url);
+       basename = gs_screenshot_get_cachefn_for_url (url);
        if (ssimg->width == G_MAXUINT || ssimg->height == G_MAXUINT) {
                sizedir = g_strdup ("unknown");
        } else {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]