diff options
author | Kim Woelders <kim@woelders.dk> | 2021-07-10 15:24:03 +0200 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2021-07-10 15:40:37 +0200 |
commit | 407533ebdc9882e8567dd309154c9c3881c31027 (patch) | |
tree | b1a895c67804052a94d85a76d933adf6b4d1e74b | |
parent | 933fc2ab1fb5ca7fb88e0ae8c47b93364baaced3 (diff) | |
download | imlib2-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.c | 20 |
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)) |