mirror of
https://github.com/microsoft/mimalloc.git
synced 2024-12-27 05:11:11 +08:00
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:
parent
d3715132d1
commit
3eb616f2bf
@ -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);
|
||||||
|
@ -403,12 +403,14 @@ 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 (adjust < block_size) {
|
if (psize - adjust >= block_size) {
|
||||||
p += adjust;
|
if (adjust < block_size) {
|
||||||
psize -= adjust;
|
p += adjust;
|
||||||
if (pre_size != NULL) *pre_size = adjust;
|
psize -= adjust;
|
||||||
|
if (pre_size != NULL) *pre_size = adjust;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user