diff options
author | Simon McVittie <smcv@debian.org> | 2019-01-25 19:09:54 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2019-11-02 10:12:41 +0000 |
commit | 9b1ad57663e89caa53a4f655f20396aa2e7972b3 (patch) | |
tree | cc6b436f342c4d2e045574bff90c3813601509d8 | |
parent | 10ca2eeabb51a06dce835c9eae82b524f0aaa357 (diff) |
Revert "Stop building the icon validator"
This reverts commit 2fb498f92f8e1c41049dedf887690083fa12f6d1.
Gbp-Pq: Name Revert-Stop-building-the-icon-validator.patch
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/Makefile.am.inc | 5 | ||||
-rw-r--r-- | src/validate-icon.c | 53 |
3 files changed, 59 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 02808ab..a8a62b0 100644 --- a/configure.ac +++ b/configure.ac @@ -142,6 +142,7 @@ fi GLIB_TESTS PKG_CHECK_MODULES(FUSE, [fuse]) +PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0]) AC_CONFIG_FILES([ Makefile diff --git a/src/Makefile.am.inc b/src/Makefile.am.inc index da49bcf..a8242f1 100644 --- a/src/Makefile.am.inc +++ b/src/Makefile.am.inc @@ -1,5 +1,6 @@ libexec_PROGRAMS += \ xdg-desktop-portal \ + xdg-desktop-portal-validate-icon \ $(NULL) service_in_files += \ @@ -200,3 +201,7 @@ xdg_desktop_portal_CPPFLAGS = \ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \ -DLOCALEDIR=\"$(localedir)\" \ $(NULL) + +xdg_desktop_portal_validate_icon_SOURCES = src/validate-icon.c +xdg_desktop_portal_validate_icon_LDADD = $(GDK_PIXBUF_LIBS) +xdg_desktop_portal_validate_icon_CFLAGS = $(GDK_PIXBUF_CFLAGS) diff --git a/src/validate-icon.c b/src/validate-icon.c new file mode 100644 index 0000000..2bab74f --- /dev/null +++ b/src/validate-icon.c @@ -0,0 +1,53 @@ +#include <gdk-pixbuf/gdk-pixbuf.h> + +static int +validate_icon (const char *filename) +{ + GdkPixbufFormat *format; + int width, height; + const char *name; + const char *allowed_formats[] = { "png", "jpeg", "svg", NULL }; + g_autoptr(GdkPixbuf) pixbuf = NULL; + g_autoptr(GError) error = NULL; + + format = gdk_pixbuf_get_file_info (filename, &width, &height); + if (format == NULL) + { + g_printerr ("Format not recognized\n"); + return 1; + } + + name = gdk_pixbuf_format_get_name (format); + if (!g_strv_contains (allowed_formats, name)) + { + g_printerr ("Format %s not allowed\n", name); + return 1; + } + + if (width > 256 || height > 256) + { + g_printerr ("Image too large (%dx%d)\n", width, height); + return 1; + } + + pixbuf = gdk_pixbuf_new_from_file (filename, &error); + if (pixbuf == NULL) + { + g_printerr ("Failed to load image: %s\n", error->message); + return 1; + } + + return 0; +} + +int +main (int argc, char *argv[]) +{ + if (argc != 2) + { + g_error ("Expect a single path"); + return 1; + } + + return validate_icon (argv[1]); +} |