cap max stack size at 32 bit limit (#17019)
authorGershom Bazerman <gershomb@gmail.com>
Thu, 22 Aug 2019 16:49:04 +0000 (12:49 -0400)
committergershomb <gershomb@gmail.com>
Sun, 1 Sep 2019 04:34:05 +0000 (00:34 -0400)
rts/RtsFlags.c

index 5cdf08e..cbc9a33 100644 (file)
@@ -134,6 +134,9 @@ void initRtsFlagsDefaults(void)
     // if getPhysicalMemorySize fails just move along with an 8MB limit
     if (maxStkSize == 0)
         maxStkSize = 8 * 1024 * 1024;
+    // GcFlags.maxStkSiz is 32-bit, so we need to cap to prevent overflow (#17019)
+    else if (maxStkSize > UINT32_MAX * sizeof(W_))
+        maxStkSize = UINT32_MAX * sizeof(W_);
 
     RtsFlags.GcFlags.statsFile          = NULL;
     RtsFlags.GcFlags.giveStats          = NO_GC_STATS;
@@ -1041,7 +1044,7 @@ error = true;
               case 'K':
                   OPTION_UNSAFE;
                   RtsFlags.GcFlags.maxStkSize =
-                      decodeSize(rts_argv[arg], 2, 0, HS_WORD_MAX)
+                      decodeSize(rts_argv[arg], 2, 0, UINT32_MAX)
                       / sizeof(W_);
                   break;