diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-07-16 09:32:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-07-16 09:38:07 +0300 |
commit | 75520894c72ae8ee96cda7ed8cf8ac642c4f31ab (patch) | |
tree | daf8b438f0dcbb5632886a95231195f26cee5aa0 | |
parent | 2811de6e5c2a114a8612fffc7b317e9f91943d1e (diff) |
Fix T78636: Crash displaying many aligned buttons
Displaying user preferences search crashed on macOS when the search
contained a common character such as 'E'.
This caused alignment to 'alloca' too much memory.
Replace with a heap allocation fallback.
-rw-r--r-- | source/blender/editors/interface/interface_align.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c index 59436276277..8edae5d8740 100644 --- a/source/blender/editors/interface/interface_align.c +++ b/source/blender/editors/interface/interface_align.c @@ -31,6 +31,8 @@ #include "interface_intern.h" +#include "MEM_guardedalloc.h" + #ifdef USE_UIBUT_SPATIAL_ALIGN /** @@ -416,7 +418,16 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) return; } - butal_array = alloca(sizeof(*butal_array) * (size_t)num_buttons); + /* Note that this is typically less than ~20, and almost always under ~100. + * Even so, we can't ensure this value won't exceed available stack memory. + * Fallback to allocation instead of using #alloca, see: T78636. */ + ButAlign butal_array_buf[256]; + if (num_buttons <= ARRAY_SIZE(butal_array_buf)) { + butal_array = butal_array_buf; + } + else { + butal_array = MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__); + } memset(butal_array, 0, sizeof(*butal_array) * (size_t)num_buttons); /* Second loop: we initialize our ButAlign data for each button. */ @@ -515,6 +526,9 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) } } } + if (butal_array_buf != butal_array) { + MEM_freeN(butal_array); + } } # undef SIDE_TO_UI_BUT_ALIGN |