From c6e7fc97443ebc5ae44c07fc81b3e7eb2cf4f325 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 22 Dec 2021 13:49:52 -0700 Subject: [PATCH] Fix: Large stack allocation in compositor When COM_EXPORT_GRAPHVIZ is enabled, DebugInfo::graphviz uses a char[1000000] as local variable. When this function is called this is allocated on the stack, which has a size of just 1MB on mac and may cause a stack overflow. This patch allocates the memory on the heap and frees the memory at the end of the function. Reviewed By: LazyDodo Differential Revision: https://developer.blender.org/D13628 --- source/blender/compositor/intern/COM_Debug.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/compositor/intern/COM_Debug.cc b/source/blender/compositor/intern/COM_Debug.cc index 50a69e55b2b..8525e2fde50 100644 --- a/source/blender/compositor/intern/COM_Debug.cc +++ b/source/blender/compositor/intern/COM_Debug.cc @@ -431,8 +431,9 @@ void DebugInfo::graphviz(const ExecutionSystem *system, StringRefNull name) if (!COM_EXPORT_GRAPHVIZ) { return; } - char str[1000000]; - if (graphviz_system(system, str, sizeof(str) - 1)) { + const int max_textlength = 1000000; + char *str = (char *)MEM_mallocN(max_textlength, __func__); + if (graphviz_system(system, str, max_textlength - 1)) { char basename[FILE_MAX]; char filename[FILE_MAX]; @@ -451,6 +452,7 @@ void DebugInfo::graphviz(const ExecutionSystem *system, StringRefNull name) fputs(str, fp); fclose(fp); } + MEM_freeN(str); } static std::string get_operations_export_dir()