From 02fbaede8f33b4acc3421e6d641dfa9359a264da Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 2 May 2011 10:22:49 +0000 Subject: workaround [#27203] Crashes with some high-res image thumbnail generation skip generating thumbs for images over 100mb. also pass string lengths as size_t rather then int for path_util.c functions. --- source/blender/blenlib/BLI_path_util.h | 10 +++++----- source/blender/blenlib/intern/path_util.c | 16 ++++++++-------- source/blender/imbuf/IMB_thumbs.h | 3 +++ source/blender/imbuf/intern/thumbs.c | 9 +++++++++ 4 files changed, 25 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 3e86079dcad..585f559aba9 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -109,15 +109,15 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, void BLI_make_exist(char *dir); void BLI_make_existing_file(const char *name); void BLI_split_dirfile(const char *string, char *dir, char *file); -void BLI_join_dirfile(char *string, const int maxlen, const char *dir, const char *file); +void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file); char *BLI_path_basename(char *path); -int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir); +int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir); char *BLI_last_slash(const char *string); int BLI_add_slash(char *string); void BLI_del_slash(char *string); char *BLI_first_slash(char *string); -void BLI_getlastdir(const char* dir, char *last, int maxlen); +void BLI_getlastdir(const char* dir, char *last, const size_t maxlen); int BLI_testextensie(const char *str, const char *ext); int BLI_testextensie_array(const char *str, const char **ext_array); int BLI_testextensie_glob(const char *str, const char *ext_fnmatch); @@ -195,7 +195,7 @@ void BLI_char_switch(char *string, char from, char to); * @param fullname The full path and full name of the executable * @param name The name of the executable (usually argv[0]) to be checked */ -void BLI_where_am_i(char *fullname, const int maxlen, const char *name); +void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name); char *get_install_dir(void); /** @@ -206,7 +206,7 @@ char *get_install_dir(void); * * @param fullname The full path to the temp directory */ -void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp); +void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp); #ifdef WITH_ICONV diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 1a47a93ab51..6630faf3048 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -763,7 +763,7 @@ void BLI_splitdirstring(char *di, char *fi) } } -void BLI_getlastdir(const char* dir, char *last, int maxlen) +void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) { const char *s = dir; const char *lslash = NULL; @@ -1441,7 +1441,7 @@ void BLI_split_dirfile(const char *string, char *dir, char *file) } /* simple appending of filename to dir, does not check for valid path! */ -void BLI_join_dirfile(char *string, const int maxlen, const char *dir, const char *file) +void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file) { int sl_dir; @@ -1491,7 +1491,7 @@ char *BLI_path_basename(char *path) that a user gets his images in one place. It'll also provide consistent behaviour across exporters. */ -int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir) +int BKE_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir) { char path[FILE_MAX]; char dir[FILE_MAX]; @@ -1547,11 +1547,11 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char } if (abs) - BLI_strncpy(abs, dest_path, abs_size); + BLI_strncpy(abs, dest_path, abs_len); if (rel) { - strncat(rel, rel_dir, rel_size); - strncat(rel, base, rel_size); + strncat(rel, rel_dir, rel_len); + strncat(rel, base, rel_len); } /* return 2 if src=dest */ @@ -1667,7 +1667,7 @@ static int add_win32_extension(char *name) } /* filename must be FILE_MAX length minimum */ -void BLI_where_am_i(char *fullname, const int maxlen, const char *name) +void BLI_where_am_i(char *fullname, const size_t maxlen, const char *name) { char filename[FILE_MAXDIR+FILE_MAXFILE]; const char *path = NULL, *temp; @@ -1756,7 +1756,7 @@ void BLI_where_am_i(char *fullname, const int maxlen, const char *name) } } -void BLI_where_is_temp(char *fullname, const int maxlen, int usertemp) +void BLI_where_is_temp(char *fullname, const size_t maxlen, int usertemp) { fullname[0] = '\0'; diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h index 583a677ebd9..f5e63b73cb1 100644 --- a/source/blender/imbuf/IMB_thumbs.h +++ b/source/blender/imbuf/IMB_thumbs.h @@ -59,6 +59,9 @@ typedef enum ThumbSource { THB_SOURCE_BLEND } ThumbSource; +/* dont generate thumbs for images bigger then this (100mb) */ +#define THUMB_SIZE_MAX (100 * 1024*1024) + // IB_metadata /* create thumbnail for file and returns new imbuf for thumbnail */ diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c index 3e17665fa39..1d91f34f4fa 100644 --- a/source/blender/imbuf/intern/thumbs.c +++ b/source/blender/imbuf/intern/thumbs.c @@ -275,6 +275,15 @@ ImBuf* IMB_thumb_create(const char* path, ThumbSize size, ThumbSource source, Im return NULL; /* unknown size */ } + /* exception, skip images over 100mb */ + if(source == THB_SOURCE_IMAGE) { + const size_t size= BLI_filepathsize(path); + if(size != -1 && size > THUMB_SIZE_MAX) { + // printf("file too big: %d, skipping %s\n", (int)size, path); + return NULL; + } + } + uri_from_filename(path, uri); thumbname_from_uri(uri, thumb, sizeof(thumb)); if (get_thumb_dir(tdir, size)) { -- cgit v1.2.3