Commit d95a7f13 authored by Simon Marlow's avatar Simon Marlow
Browse files

Avoid integer overflow when calling allocGroup() (#5071)

parent a02eb298
......@@ -14,7 +14,11 @@ OutOfHeapHook (lnat request_size, lnat heap_size) /* both sizes in bytes */
/* fprintf(stderr, "Heap exhausted;\nwhile trying to allocate %lu bytes in a %lu-byte heap;\nuse `+RTS -H<size>' to increase the total heap size.\n", */
(void)request_size; /* keep gcc -Wall happy */
fprintf(stderr, "Heap exhausted;\nCurrent maximum heap size is %lu bytes (%lu MB);\nuse `+RTS -M<size>' to increase it.\n",
heap_size, heap_size / (1024*1024));
if (heap_size > 0) {
errorBelch("Heap exhausted;\nCurrent maximum heap size is %lu bytes (%lu MB);\nuse `+RTS -M<size>' to increase it.",
heap_size, heap_size / (1024*1024));
} else {
errorBelch("out of memory");
}
}
......@@ -627,8 +627,11 @@ allocate (Capability *cap, lnat n)
// Attempting to allocate an object larger than maxHeapSize
// should definitely be disallowed. (bug #1791)
if (RtsFlags.GcFlags.maxHeapSize > 0 &&
req_blocks >= RtsFlags.GcFlags.maxHeapSize) {
if ((RtsFlags.GcFlags.maxHeapSize > 0 &&
req_blocks >= RtsFlags.GcFlags.maxHeapSize) ||
req_blocks >= HS_INT32_MAX) // avoid overflow when
// calling allocGroup() below
{
heapOverflow();
// heapOverflow() doesn't exit (see #2592), but we aren't
// in a position to do a clean shutdown here: we
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment