kwo pushed a commit to branch master.

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

commit d56be3b8df21bf62f05b03d41ab5a2322ad92fc6
Author: Kim Woelders <[email protected]>
Date:   Thu Apr 7 10:34:57 2022 +0200

    loaders: Ensure that found loader is ok for load/save
    
    Fixes a segv that could happen if trying to save an image with a not
    previously loaded loader that has no saver.
    Bug since v1.7.5.
---
 src/lib/loaders.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/lib/loaders.c b/src/lib/loaders.c
index 1003a63..2437a1a 100644
--- a/src/lib/loaders.c
+++ b/src/lib/loaders.c
@@ -280,6 +280,12 @@ __imlib_LookupKnownLoader(const char *format)
    return l;
 }
 
+static int
+_loader_ok_for(const ImlibLoader * l, int for_save)
+{
+   return (for_save && l->save) || (!for_save && (l->load2 || l->load));
+}
+
 static ImlibLoader *
 __imlib_LookupLoadedLoader(const char *format, int for_save)
 {
@@ -310,8 +316,7 @@ __imlib_LookupLoadedLoader(const char *format, int for_save)
              if (strcasecmp(l->formats[i], format) == 0)
                {
                   /* does it provide the function we need? */
-                  if ((for_save && l->save) ||
-                      (!for_save && (l->load2 || l->load)))
+                  if (_loader_ok_for(l, for_save))
                      goto done;
                }
           }
@@ -344,7 +349,7 @@ __imlib_FindBestLoader(const char *file, const char 
*format, int for_save)
      }
 
    l = __imlib_LookupKnownLoader(format);
-   if (l)
+   if (l && _loader_ok_for(l, for_save))
       goto done;
 
    __imlib_LoadAllLoaders();

-- 


Reply via email to