summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2019-10-15 20:08:43 +0200
committerKim Woelders <kim@woelders.dk>2019-10-15 20:39:44 +0200
commit5e267577bdaa6ce5bb9e5fc238d7a58408f2fd27 (patch)
tree01d565298e26e06ad035f2fff1fae0741da32eef
parentff3164df37947bb7ba1e5445a76545ccaf22d8e6 (diff)
GZIP loader: Check filename before uncompressHEADmaster
Inspired by corresponding bz2 loader fix. Also remove pointless call to stat().
-rw-r--r--src/modules/loaders/loader_zlib.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/modules/loaders/loader_zlib.c b/src/modules/loaders/loader_zlib.c
index 29c39a0..aba9583 100644
--- a/src/modules/loaders/loader_zlib.c
+++ b/src/modules/loaders/loader_zlib.c
@@ -42,10 +42,10 @@ load(ImlibImage * im, ImlibProgressFunction progress,
42 char progress_granularity, char immediate_load) 42 char progress_granularity, char immediate_load)
43{ 43{
44 ImlibLoader *loader; 44 ImlibLoader *loader;
45 int src, dest, res; 45 int src;
46 int dest, res;
46 char *file, *p, *q, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX"; 47 char *file, *p, *q, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX";
47 char *real_ext; 48 char *real_ext;
48 struct stat st;
49 49
50 /* check that this file ends in *.gz and that there's another ext 50 /* check that this file ends in *.gz and that there's another ext
51 * (e.g. "foo.png.gz" 51 * (e.g. "foo.png.gz"
@@ -55,17 +55,25 @@ load(ImlibImage * im, ImlibProgressFunction progress,
55 if (!p || p == im->real_file || strcasecmp(p + 1, "gz") || p == q) 55 if (!p || p == im->real_file || strcasecmp(p + 1, "gz") || p == q)
56 return 0; 56 return 0;
57 57
58 if (stat(im->real_file, &st) < 0) 58 if (!(real_ext = strndup(im->real_file, p - im->real_file)))
59 return 0; 59 return 0;
60 60
61 if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
62 {
63 free(real_ext);
64 return 0;
65 }
66
61 if ((src = open(im->real_file, O_RDONLY)) < 0) 67 if ((src = open(im->real_file, O_RDONLY)) < 0)
62 { 68 {
69 free(real_ext);
63 return 0; 70 return 0;
64 } 71 }
65 72
66 if ((dest = mkstemp(tmp)) < 0) 73 if ((dest = mkstemp(tmp)) < 0)
67 { 74 {
68 close(src); 75 close(src);
76 free(real_ext);
69 return 0; 77 return 0;
70 } 78 }
71 79
@@ -75,15 +83,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
75 83
76 if (!res) 84 if (!res)
77 { 85 {
78 unlink(tmp);
79 return 0;
80 }
81
82 if (!(real_ext = strndup(im->real_file, p - im->real_file)))
83 return 0;
84
85 if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
86 {
87 free(real_ext); 86 free(real_ext);
88 unlink(tmp); 87 unlink(tmp);
89 return 0; 88 return 0;