[gnome-software: 2/4] gs-appstream: Fix handling of icons where appdata doesn’t specify width




commit 9a63168893a678f97fe6e3bfde2d6e5debf151c3
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Mar 16 13:34:13 2021 +0000

    gs-appstream: Fix handling of icons where appdata doesn’t specify width
    
    If the `<icon>` element in the appdata doesn’t specify a `width`
    attribute, `xb_node_get_attr_as_uint()` will return `G_MAXUINT64`.
    However, its return value was being assigned to `sz`, which is a
    `guint`, and hence it was being truncated. This resulted in icons having
    their widths set to `G_MAXUINT`, and hence being prioritised for display
    when that was not necessarily correct.
    
    Fix that by explicitly handling the failure response from
    `xb_node_get_attr_as_uint()`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #1171

 plugins/core/gs-appstream.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/plugins/core/gs-appstream.c b/plugins/core/gs-appstream.c
index a9cf97270..22fed1154 100644
--- a/plugins/core/gs-appstream.c
+++ b/plugins/core/gs-appstream.c
@@ -149,8 +149,12 @@ gs_appstream_new_icon (XbNode *component, XbNode *n, AsIconKind icon_kind, guint
        default:
                as_icon_set_name (icon, xb_node_get_text (n));
        }
-       if (sz == 0)
-               sz = xb_node_get_attr_as_uint (n, "width");
+       if (sz == 0) {
+               guint64 width = xb_node_get_attr_as_uint (n, "width");
+               if (width > 0 && width < G_MAXUINT)
+                       sz = width;
+       }
+
        if (sz > 0) {
                as_icon_set_width (icon, sz);
                as_icon_set_height (icon, sz);


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