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
This commit is contained in:
Olof-Joachim Frahm (欧雅福) 2019-10-15 16:58:14 +02:00 committed by Kim Woelders
parent ab918a65ac
commit ff3164df37
1 changed files with 11 additions and 9 deletions

View File

@ -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);