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>
This commit is contained in:
NRK 2022-10-21 08:02:54 +02:00
parent b11384a694
commit e197429489
1 changed files with 3 additions and 9 deletions

10
image.c
View File

@ -412,16 +412,10 @@ Imlib_Image img_open(const fileinfo_t *file)
Imlib_Image im = NULL; Imlib_Image im = NULL;
if (access(file->path, R_OK) == 0 && 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); imlib_context_set_image(im);
if (imlib_image_get_data_for_reading_only() == NULL) {
imlib_free_image();
im = NULL;
}
}
} }
if (im == NULL && (file->flags & FF_WARN)) if (im == NULL && (file->flags & FF_WARN))
error(0, 0, "%s: Error opening image", file->name); error(0, 0, "%s: Error opening image", file->name);