From 1e636c45da16e1f3dfbc8ff8aeca58a8d28f1ecc Mon Sep 17 00:00:00 2001 From: daan Date: Thu, 27 Jun 2019 13:33:28 -0700 Subject: [PATCH] add check for overflowing size allocation --- src/page.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/page.c b/src/page.c index 85b810e1..6b416251 100644 --- a/src/page.c +++ b/src/page.c @@ -694,7 +694,12 @@ void* _mi_malloc_generic(mi_heap_t* heap, size_t size) mi_attr_noexcept // huge allocation? mi_page_t* page; if (mi_unlikely(size > MI_LARGE_SIZE_MAX)) { - page = mi_huge_page_alloc(heap,size); + if (mi_unlikely(size >= (SIZE_MAX - MI_MAX_ALIGN_SIZE))) { + page = NULL; + } + else { + page = mi_huge_page_alloc(heap,size); + } } else { // otherwise find a page with free blocks in our size segregated queues