@minlexx
Copy link

minlexx commented Apr 16, 2022

Symptom: screenshot URLs look like this (note double https://) (sreenshot from debugger session)
image

As we can see in src/as-image.c#L342 base url is appended unconditinally, resulting in screenshot image that cannot be downloaded and degraded user experience in software center application (plasma-discover in our case).

Metadata XML fragment for this looks like:

<screenshot type="default">
      <image type="source">https://cdn.kde.org/screenshots/ktorrent/ktorrent.png</image>
      <image type="source" width="766" height="541">org/kde/ktorrent.desktop/214435abe2b8d85089dc352adbfb4873/screenshots/image-1_orig.png</image>
      <image type="thumbnail" width="752" height="531">org/kde/ktorrent.desktop/214435abe2b8d85089dc352adbfb4873/screenshots/image-1_752x531.png</image>
      <image type="thumbnail" width="624" height="440">org/kde/ktorrent.desktop/214435abe2b8d85089dc352adbfb4873/screenshots/image-1_624x440.png</image>
      <image type="thumbnail" width="224" height="158">org/kde/ktorrent.desktop/214435abe2b8d85089dc352adbfb4873/screenshots/image-1_224x158.png</image>
</screenshot>

The issue can be reproduced by small example program that loads single metadata file:

test: Pool default flags:  "FlagLoadOsCollection | FlagLoadOsMetainfo | FlagLoadFlatpak"
test: Pool new flags:  "FlagLoadOsCollection"
test: Adding extra metadata path:  "/home/lexx/dev/test/build-test_appstream-System_Qt-Debug/metadata"
test: Loaded total  1  components
test: Found ktorrent  1  times
test:    "org.kde.ktorrent.desktop"
test:      "KindSource" ; url:  "https://appstream.alpinelinux.org/media/edge/https://cdn.kde.org/screenshots/ktorrent/ktorrent.png"
test:      "KindSource" ; url:  "https://appstream.alpinelinux.org/media/edge/org/kde/ktorrent.desktop/2250ef363428df697ba6e87d1d66e821/screenshots/image-1_orig.png"
test:      "KindThumbnail" ; url:  "https://appstream.alpinelinux.org/media/edge/org/kde/ktorrent.desktop/2250ef363428df697ba6e87d1d66e821/screenshots/image-1_752x531.png"
test:      "KindThumbnail" ; url:  "https://appstream.alpinelinux.org/media/edge/org/kde/ktorrent.desktop/2250ef363428df697ba6e87d1d66e821/screenshots/image-1_624x440.png"
test:      "KindThumbnail" ; url:  "https://appstream.alpinelinux.org/media/edge/org/kde/ktorrent.desktop/2250ef363428df697ba6e87d1d66e821/screenshots/image-1_224x158.png"

As you can see also from test example, first screenshot URL has extra https:// added.

Suggested fix is by checking for absolute URL with g_str_has_prefix (or whatever the correct way in glib is, I'm Qt user, don't know much about glib). In case if screenshot URL is already starting with https://, do not append media_baseurl.

P.S. downstream issue for reference: https://gitlab.alpinelinux.org/alpine/infra/compose/appstream-generator/-/issues/2