fix bug in secure mode where adjustment would make the page size less than the blocksize on the first page of a segment

This commit is contained in:
Daan 2022-11-06 14:51:06 -08:00
parent d3715132d1
commit 3eb616f2bf
2 changed files with 8 additions and 5 deletions

View File

@ -646,6 +646,7 @@ static void mi_page_init(mi_heap_t* heap, mi_page_t* page, size_t block_size, mi
page->xblock_size = (block_size < MI_HUGE_BLOCK_SIZE ? (uint32_t)block_size : MI_HUGE_BLOCK_SIZE); page->xblock_size = (block_size < MI_HUGE_BLOCK_SIZE ? (uint32_t)block_size : MI_HUGE_BLOCK_SIZE);
mi_assert_internal(page_size / block_size < (1L<<16)); mi_assert_internal(page_size / block_size < (1L<<16));
page->reserved = (uint16_t)(page_size / block_size); page->reserved = (uint16_t)(page_size / block_size);
mi_assert_internal(page->reserved > 0);
#ifdef MI_ENCODE_FREELIST #ifdef MI_ENCODE_FREELIST
page->keys[0] = _mi_heap_random_next(heap); page->keys[0] = _mi_heap_random_next(heap);
page->keys[1] = _mi_heap_random_next(heap); page->keys[1] = _mi_heap_random_next(heap);

View File

@ -403,6 +403,7 @@ uint8_t* _mi_segment_page_start(const mi_segment_t* segment, const mi_page_t* pa
if (page->segment_idx == 0 && block_size > 0 && segment->page_kind <= MI_PAGE_MEDIUM) { if (page->segment_idx == 0 && block_size > 0 && segment->page_kind <= MI_PAGE_MEDIUM) {
// for small and medium objects, ensure the page start is aligned with the block size (PR#66 by kickunderscore) // for small and medium objects, ensure the page start is aligned with the block size (PR#66 by kickunderscore)
size_t adjust = block_size - ((uintptr_t)p % block_size); size_t adjust = block_size - ((uintptr_t)p % block_size);
if (psize - adjust >= block_size) {
if (adjust < block_size) { if (adjust < block_size) {
p += adjust; p += adjust;
psize -= adjust; psize -= adjust;
@ -410,6 +411,7 @@ uint8_t* _mi_segment_page_start(const mi_segment_t* segment, const mi_page_t* pa
} }
mi_assert_internal((uintptr_t)p % block_size == 0); mi_assert_internal((uintptr_t)p % block_size == 0);
} }
}
if (page_size != NULL) *page_size = psize; if (page_size != NULL) *page_size = psize;
mi_assert_internal(page->xblock_size==0 || _mi_ptr_page(p) == page); mi_assert_internal(page->xblock_size==0 || _mi_ptr_page(p) == page);