Skip to content

Issue #876: Fix integer overflow on slice_count #877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ static mi_segment_t* mi_segment_os_alloc( size_t required, size_t page_alignment
const size_t extra = align_offset - info_size;
// recalculate due to potential guard pages
*psegment_slices = mi_segment_calculate_slices(required + extra, ppre_size, pinfo_slices);

// gh-876: mi_page_t.slice_count type is uint32_t
if (*psegment_slices > (size_t)UINT32_MAX) return NULL;
}

const size_t segment_size = (*psegment_slices) * MI_SEGMENT_SLICE_SIZE;
Expand Down Expand Up @@ -870,6 +873,9 @@ static mi_segment_t* mi_segment_alloc(size_t required, size_t page_alignment, mi
size_t pre_size;
size_t segment_slices = mi_segment_calculate_slices(required, &pre_size, &info_slices);

// gh-876: mi_page_t.slice_count type is uint32_t
if (segment_slices > (size_t)UINT32_MAX) return NULL;

// Commit eagerly only if not the first N lazy segments (to reduce impact of many threads that allocate just a little)
const bool eager_delay = (// !_mi_os_has_overcommit() && // never delay on overcommit systems
_mi_current_thread_count() > 1 && // do not delay for the first N threads
Expand Down
Loading