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.
+3 −9
1 file changed
- M image.c +3 −9
| @@ -412,16 +412,10 @@ Imlib_Image img_open(const fileinfo_t *file) | |||
| 412 | 412 | Imlib_Image im = NULL; | |
| 413 | 413 | ||
| 414 | 414 | 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) | |
| 416 | 417 | { | |
| 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); | |
| 425 | 419 | } | |
| 426 | 420 | if (im == NULL && (file->flags & FF_WARN)) | |
| 427 | 421 | error(0, 0, "%s: Error opening image", file->name); | |