kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=43f82f3bc80324282ec22cb6b7c0e0b3ca2b663f

commit 43f82f3bc80324282ec22cb6b7c0e0b3ca2b663f
Author: Kim Woelders <k...@woelders.dk>
Date:   Sun Sep 12 07:04:36 2021 +0200

    GIF, TIFF, WEBP loaders: Fix loading if filename does not have usual suffix
    
    Patch from Daniel Friesel <d...@finalrewind.org>:
    
    ---
    Fix .gif loader if filename does not end in .gif
    
    Imlib2 is currently unable to load gif images if the filename does not end 
in
    .gif. This appears to be caused by imlib2 not resetting the file descriptor
    back to 0 after trying to open the image with its different loaders.
    
    While imlib2 does call rewind(FILE* im->fp) before invoking each loader, 
this
    does not guarantee that the underlying FD is seeked as well. However, the 
GIF
    loader uses the FD directly, and therefore tries to read from the middle of 
the
    file (unless it is the first loader). This patch adds an explicit seek in 
the
    same fashion as implemented in the TIFF loader.
    
    Patch and debugging credits go to Lars Stoltenow.
    ---
    
    Also fix same issue in TIFF and WEBP loaders.
---
 src/modules/loaders/loader_gif.c  | 1 +
 src/modules/loaders/loader_tiff.c | 1 +
 src/modules/loaders/loader_webp.c | 2 ++
 3 files changed, 4 insertions(+)

diff --git a/src/modules/loaders/loader_gif.c b/src/modules/loaders/loader_gif.c
index cc8baa7..fbac9cc 100644
--- a/src/modules/loaders/loader_gif.c
+++ b/src/modules/loaders/loader_gif.c
@@ -18,6 +18,7 @@ load2(ImlibImage * im, int load_data)
    DATA32              colormap[256];
 
    fd = dup(fileno(im->fp));
+   lseek(fd, 0, SEEK_SET);
 
 #if GIFLIB_MAJOR >= 5
    gif = DGifOpenFileHandle(fd, NULL);
diff --git a/src/modules/loaders/loader_tiff.c 
b/src/modules/loaders/loader_tiff.c
index 2b76a4c..2cbe6e2 100644
--- a/src/modules/loaders/loader_tiff.c
+++ b/src/modules/loaders/loader_tiff.c
@@ -247,6 +247,7 @@ load2(ImlibImage * im, int load_data)
    rgba_image.image = NULL;
 
    fd = fileno(im->fp);
+   lseek(fd, 0, SEEK_SET);
    if (read(fd, &magic_number, sizeof(uint16_t)) != sizeof(uint16_t))
       goto quit;
 
diff --git a/src/modules/loaders/loader_webp.c 
b/src/modules/loaders/loader_webp.c
index de0c13b..49f8136 100644
--- a/src/modules/loaders/loader_webp.c
+++ b/src/modules/loaders/loader_webp.c
@@ -53,6 +53,8 @@ load2(ImlibImage * im, int load_data)
    if (!encoded_data)
       goto quit;
 
+   lseek(fd, 0, SEEK_SET);
+
    /* Check signature */
    size = 12;
    if (read(fd, encoded_data, size) != (long)size)

-- 


Reply via email to