summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-07-10 15:24:03 +0200
committerKim Woelders <kim@woelders.dk>2021-07-10 15:40:37 +0200
commit407533ebdc9882e8567dd309154c9c3881c31027 (patch)
treeb1a895c67804052a94d85a76d933adf6b4d1e74b
parent933fc2ab1fb5ca7fb88e0ae8c47b93364baaced3 (diff)
downloadimlib2-407533ebdc9882e8567dd309154c9c3881c31027.tar.gz
TGA loader: Fix loading small images without footer
Patch by noospot <noospot@mail.de>.
-rw-r--r--src/modules/loaders/loader_tga.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/modules/loaders/loader_tga.c b/src/modules/loaders/loader_tga.c
index e9729b0..8d96196 100644
--- a/src/modules/loaders/loader_tga.c
+++ b/src/modules/loaders/loader_tga.c
@@ -188,7 +188,7 @@ load2(ImlibImage * im, int load_data)
if (fstat(fd, &ss) < 0)
goto quit;
- if (ss.st_size < (long)(sizeof(tga_header) + sizeof(tga_footer)) ||
+ if (ss.st_size < (long)(sizeof(tga_header)) ||
(uintmax_t) ss.st_size > SIZE_MAX)
goto quit;
@@ -198,11 +198,21 @@ load2(ImlibImage * im, int load_data)
filedata = seg;
header = (tga_header *) filedata;
- footer = (tga_footer *) ((char *)filedata + ss.st_size - sizeof(tga_footer));
- /* check the footer to see if we have a v2.0 TGA file */
- footer_present =
- memcmp(footer->signature, TGA_SIGNATURE, sizeof(footer->signature)) == 0;
+ if (ss.st_size > (long)(sizeof(tga_footer)))
+ {
+ footer =
+ (tga_footer *) ((char *)filedata + ss.st_size - sizeof(tga_footer));
+
+ /* check the footer to see if we have a v2.0 TGA file */
+ footer_present =
+ memcmp(footer->signature, TGA_SIGNATURE,
+ sizeof(footer->signature)) == 0;
+ }
+ else
+ {
+ footer_present = 0;
+ }
if ((size_t)ss.st_size < sizeof(tga_header) + header->idLength +
(footer_present ? sizeof(tga_footer) : 0))