From f02661879ff0efefc6751d927c2e721e64ad79f0 Mon Sep 17 00:00:00 2001 From: Bert Münnich Date: Thu, 23 Nov 2017 14:35:32 +0100 Subject: Reject text files resembling TGA images Fixes issue #295 The imlib2 TGA loader returns an imlib image handle without any actual data when given a text file like this: T Content-Type: application/javascript Content-Length: 3836 Last-Modified: Wed, 23 Sep 2015 12:25:47 GMT Etag: "56029a4b-efc" Expires: Sat, 20 Aug 2016 15:14:33 GMT Cache-Control: max-age=604800, public Accept-Ranges: bytes Fortunately, `imlib_image_get_data()` returns NULL in this case, so that we can use it as an additional check when opening files. --- thumbs.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'thumbs.c') diff --git a/thumbs.c b/thumbs.c index a99c764..37be29f 100644 --- a/thumbs.c +++ b/thumbs.c @@ -32,6 +32,7 @@ #include void exif_auto_orientate(const fileinfo_t*); #endif +Imlib_Image img_open(const fileinfo_t*); static char *cache_dir; @@ -237,7 +238,6 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) char *cfile; thumb_t *t; fileinfo_t *file; - struct stat st; Imlib_Image im = NULL; if (n < 0 || n >= *tns->cnt) @@ -331,14 +331,8 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only) } if (im == NULL) { - if (access(file->path, R_OK) == -1 || - stat(file->path, &st) == -1 || !S_ISREG(st.st_mode) || - (im = imlib_load_image(file->path)) == NULL) - { - if (file->flags & FF_WARN) - error(0, 0, "%s: Error opening image", file->name); + if ((im = img_open(file)) == NULL) return false; - } } imlib_context_set_image(im); -- cgit v1.2.3-54-g00ecf