aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2022-10-21 08:02:54 +0200
committerNRK <nrk@disroot.org>2022-10-21 08:02:54 +0200
commite197429489e098b2a0190330606f7022d3909644 (patch)
tree9098405dc62fb64d37a96a82642f13f736af0f83
parentb11384a6942cdf3c6b6f55e0dcc0a438eff7158a (diff)
downloadnsxiv-e197429489e098b2a0190330606f7022d3909644.tar.zst
img_open: explicitly decode image data immediately (#380)
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 <berke.kocaoglu@metu.edu.tr>
-rw-r--r--image.c12
1 files 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);