css: Remove crashy resource:// optimization
authorBenjamin Otte <otte@redhat.com>
Fri, 12 May 2023 17:20:58 +0000 (19:20 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Mon, 5 Jun 2023 11:52:05 +0000 (07:52 -0400)
Using gdk_texture_new_from_resource() is not valid here because we are
not sure if the given resource is valid.

Plus, the previous optimization is no longer relevant, because we are
not using gdk_pixbuf_new_from_resource() anymore - which was what this
optimization was about before it was ported to GdkTexture.

Test attached.

gtk/gtkcssimageurl.c
testsuite/css/parser/meson.build
testsuite/css/parser/resource-url.css [new file with mode: 0644]
testsuite/css/parser/resource-url.ref.css [new file with mode: 0644]

index d6a03c348360802dedf0fe64d0a3a0cdb3ef084e..d0dbe2a26ce01816961880f699e551486d7559fb 100644 (file)
@@ -47,21 +47,7 @@ gtk_css_image_url_load_image (GtkCssImageUrl  *url,
       return url->loaded_image;
     }
 
-  /* We special case resources here so we can use gdk_texture_new_from_resource. */
-  if (g_file_has_uri_scheme (url->file, "resource"))
-    {
-      char *uri = g_file_get_uri (url->file);
-      char *resource_path = g_uri_unescape_string (uri + strlen ("resource://"), NULL);
-
-      texture = gdk_texture_new_from_resource (resource_path);
-
-      g_free (resource_path);
-      g_free (uri);
-    }
-  else
-    {
-      texture = gdk_texture_new_from_file (url->file, &local_error);
-    }
+  texture = gdk_texture_new_from_file (url->file, &local_error);
 
   if (texture == NULL)
     {
index b419c29865e534190d44aa6d8f7c3eb9a460d7d2..4c13342c54bc4d70a3df677b46f88872c95a9738 100644 (file)
@@ -449,6 +449,8 @@ test_data = [
   'radial-positions.errors',
   'radial-positions.ref.css',
   'radial.ref.css',
+  'resource-url.css',
+  'resource-url.ref.css',
   'rotate3d-crash.css',
   'rotate3d-crash.errors',
   'rotate3d-crash.ref.css',
diff --git a/testsuite/css/parser/resource-url.css b/testsuite/css/parser/resource-url.css
new file mode 100644 (file)
index 0000000..0454116
--- /dev/null
@@ -0,0 +1,3 @@
+window { background-image: url("resource://"); }
+
+button { background-image: url("resource://doesnotexist.jpg"); }
diff --git a/testsuite/css/parser/resource-url.ref.css b/testsuite/css/parser/resource-url.ref.css
new file mode 100644 (file)
index 0000000..439229a
--- /dev/null
@@ -0,0 +1,7 @@
+window {
+  background-image: none /* invalid image */;
+}
+
+button {
+  background-image: none /* invalid image */;
+}