kwo pushed a commit to branch master.

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

commit ff3164df37947bb7ba1e5445a76545ccaf22d8e6
Author: Olof-Joachim Frahm (欧雅福) <[email protected]>
Date:   Tue Oct 15 16:58:14 2019 +0200

    Check filename before opening archive file.
    
    Summary:
    Decompressing should be the last step, otherwise files that can't even be 
loaded will take unnecessarily long only to be discarded immediately.
    
    This is in reference to [this issue for 
feh](https://github.com/derf/feh/issues/477) complaining about long load times 
in case of accidentally trying to open a big .tar.bz2 archive.
    
    Test Plan: Ran on sample from aforementioned ticket, observed immediate 
response and no further ill effects.
    
    Reviewers: kwo
    
    Differential Revision: https://phab.enlightenment.org/D10398
---
 src/modules/loaders/loader_bz2.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/modules/loaders/loader_bz2.c b/src/modules/loaders/loader_bz2.c
index b3e3aba..f047f7b 100644
--- a/src/modules/loaders/loader_bz2.c
+++ b/src/modules/loaders/loader_bz2.c
@@ -62,14 +62,25 @@ load(ImlibImage * im, ImlibProgressFunction progress,
    if (!p || p == im->real_file || strcasecmp(p + 1, "bz2") || p == q)
       return 0;
 
+   if (!(real_ext = strndup(im->real_file, p - im->real_file)))
+      return 0;
+
+   if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
+     {
+        free(real_ext);
+        return 0;
+     }
+
    if (!(fp = fopen(im->real_file, "rb")))
      {
+        free(real_ext);
         return 0;
      }
 
    if ((dest = mkstemp(tmp)) < 0)
      {
         fclose(fp);
+        free(real_ext);
         return 0;
      }
 
@@ -78,15 +89,6 @@ load(ImlibImage * im, ImlibProgressFunction progress,
    close(dest);
 
    if (!res)
-     {
-        unlink(tmp);
-        return 0;
-     }
-
-   if (!(real_ext = strndup(im->real_file, p - im->real_file)))
-      return 0;
-
-   if (!(loader = __imlib_FindBestLoaderForFile(real_ext, 0)))
      {
         free(real_ext);
         unlink(tmp);

-- 


Reply via email to