kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=407533ebdc9882e8567dd309154c9c3881c31027

commit 407533ebdc9882e8567dd309154c9c3881c31027
Author: Kim Woelders <k...@woelders.dk>
Date:   Sat Jul 10 15:24:03 2021 +0200

    TGA loader: Fix loading small images without footer
    
    Patch by noospot <noos...@mail.de>.
---
 src/modules/loaders/loader_tga.c | 20 +++++++++++++++-----
 1 file 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))

-- 


Reply via email to