From 27a8ea013e05c37b3a226c2bb7749bb54e0d6a61 Mon Sep 17 00:00:00 2001 From: santouits Date: Tue, 29 Oct 2019 20:34:24 +0200 Subject: [PATCH] Fix crashing when a window icon is large If an icon of a window is large tint2 crashes with segmentation fault, I guess because of stack overflow. This changes the allocation of icon_data from stack to heap. --- src/taskbar/task.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 41a878d..065522b 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -312,10 +312,16 @@ Imlib_Image task_get_icon(Window win, int icon_size) int w, h; gulong *tmp_data = get_best_icon(data, get_icon_count(data, len), len, &w, &h, icon_size); if (tmp_data) { - DATA32 icon_data[w * h]; - for (int j = 0; j < w * h; ++j) - icon_data[j] = tmp_data[j]; - img = imlib_create_image_using_copied_data(w, h, icon_data); + int array_size = w * h; + // imlib needs the array in DATA32 type + // using malloc for the array to protect from stack overflow + DATA32 *icon_data = (DATA32*) g_try_malloc(sizeof(*icon_data) * array_size); + if (icon_data) { + for (int j = 0; j < array_size; ++j) + icon_data[j] = tmp_data[j]; + img = imlib_create_image_using_copied_data(w, h, icon_data); + g_free(icon_data); + } } } XFree(data);