From e197429489e098b2a0190330606f7022d3909644 Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 21 Oct 2022 08:02:54 +0200 Subject: [PATCH] img_open: explicitly decode image data immediately (#380) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the way `imlib_load_image()` works, is that it only does a lightweight signature/metadata check. it doesn't actually decode the image. which means that a file that has valid metadata but invalid content would get loaded successfully. `imlib_image_get_data_for_reading_only()` basically forces imlib to decode the data, and thus reveal any malformed images so we can reject it (see commit f0266187). however, this is a spurious way of achieving the goal at hand. imlib2 already offers an `_immediately` variant which decodes the data immediately. so just use that instead of spuriously using the "get_data" function to force a decode. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/380 Reviewed-by: Berke Kocaoğlu --- image.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/image.c b/image.c index 4c9e393..6c8c465 100644 --- a/image.c +++ b/image.c @@ -412,16 +412,10 @@ Imlib_Image img_open(const fileinfo_t *file) Imlib_Image im = NULL; if (access(file->path, R_OK) == 0 && - stat(file->path, &st) == 0 && S_ISREG(st.st_mode)) + stat(file->path, &st) == 0 && S_ISREG(st.st_mode) && + (im = imlib_load_image_immediately(file->path)) != NULL) { - im = imlib_load_image(file->path); - if (im != NULL) { - imlib_context_set_image(im); - if (imlib_image_get_data_for_reading_only() == NULL) { - imlib_free_image(); - im = NULL; - } - } + imlib_context_set_image(im); } if (im == NULL && (file->flags & FF_WARN)) error(0, 0, "%s: Error opening image", file->name);