Krolyxon
Commit e197429

Branches

Refs →

nsxive197429

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.
Author
NRK
Date
2022-10-21 08:02 +0200
Parent
b11384a
Commit
e197429489e098b2a0190330606f7022d3909644

+3 −9

1 file changed

  1. M image.c +3 −9
M image.c View
@@ -412,16 +412,10 @@ Imlib_Image img_open(const fileinfo_t *file)
412412 Imlib_Image im = NULL;
413413
414414 if (access(file->path, R_OK) == 0 &&
415− stat(file->path, &st) == 0 && S_ISREG(st.st_mode))
415+ stat(file->path, &st) == 0 && S_ISREG(st.st_mode) &&
416+ (im = imlib_load_image_immediately(file->path)) != NULL)
416417 {
417− im = imlib_load_image(file->path);
418− if (im != NULL) {
419− imlib_context_set_image(im);
420− if (imlib_image_get_data_for_reading_only() == NULL) {
421− imlib_free_image();
422− im = NULL;
423− }
424− }
418+ imlib_context_set_image(im);
425419 }
426420 if (im == NULL && (file->flags & FF_WARN))
427421 error(0, 0, "%s: Error opening image", file->name);