From 00120b795a811ae70db89dde5021461658f2880f Mon Sep 17 00:00:00 2001 From: Andriy Grytsenko Date: Sat, 23 Aug 2014 16:38:35 +0300 Subject: [PATCH] [SF#895]Check image sizes and abort loading image if it's Mpx is above thumbnail_max. This should be reflected in the Preferences on next strings change. --- src/base/fm-config.h | 2 +- src/base/fm-thumbnail-loader.c | 2 +- src/gtk/fm-thumbnail.c | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/base/fm-config.h b/src/base/fm-config.h index 223bc31c..9ae4c4a6 100644 --- a/src/base/fm-config.h +++ b/src/base/fm-config.h @@ -107,7 +107,7 @@ typedef enum * @small_icon_size: size of small icons * @pane_icon_size: size of side pane icons * @thumbnail_size: size of thumbnail icons - * @thumbnail_max: show thumbnails for files smaller than 'thumb_max' KB + * @thumbnail_max: show thumbnails only for files not bigger than this, in KB or Kpix * @auto_selection_delay: (since 1.2.0) delay for autoselection in single-click mode, in ms * @drop_default_action: (since 1.2.0) default action on drop (see #FmDndDestDropAction) * @single_click: single click to open file diff --git a/src/base/fm-thumbnail-loader.c b/src/base/fm-thumbnail-loader.c index 3f15855f..4064e274 100644 --- a/src/base/fm-thumbnail-loader.c +++ b/src/base/fm-thumbnail-loader.c @@ -2,7 +2,7 @@ * fm-thumbnail-loader.c * * Copyright 2010 - 2013 Hong Jen Yee (PCMan) - * Copyright 2012 Andriy Grytsenko (LStranger) + * Copyright 2012-2014 Andriy Grytsenko (LStranger) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/gtk/fm-thumbnail.c b/src/gtk/fm-thumbnail.c index 94bf1f83..de0829a1 100644 --- a/src/gtk/fm-thumbnail.c +++ b/src/gtk/fm-thumbnail.c @@ -2,7 +2,7 @@ * fm-thumbnail.c * * Copyright 2010 - 2012 Hong Jen Yee (PCMan) - * Copyright 2012 Andriy Grytsenko (LStranger) + * Copyright 2012-2014 Andriy Grytsenko (LStranger) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,7 @@ #include #endif #include "fm-thumbnail.h" +#include "fm-config.h" /* FIXME: this function prototype seems to be missing in header files of GdkPixbuf. Bug report to them. */ gboolean gdk_pixbuf_set_option(GdkPixbuf *pixbuf, const gchar *key, const gchar *value); @@ -131,6 +132,18 @@ guint fm_thumbnail_request_get_size(FmThumbnailRequest* req) } static GObject* read_image_from_file(const char* filename) { + if (fm_config->thumbnail_max > 0) + { + int w = 1 , h = 1; + + /* SF bug #895: image of big dimension can be still small due to + image compression and loading that image into memory can easily + overrun the available memory, so let limit image by Mpix as well */ + gdk_pixbuf_get_file_info(filename, &w, &h); + /* g_debug("thumbnail generator: image size %dx%d", w, h); */ + if (w * h > (fm_config->thumbnail_max << 10)) + return NULL; + } return (GObject*)gdk_pixbuf_new_from_file(filename, NULL); }