Skip to content

Commit 7773e00

Browse files
committed
Backport upstream fix for ubsan
1 parent f62a1e8 commit 7773e00

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Objects/mimalloc/segment.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ static mi_page_t* mi_segment_span_allocate(mi_segment_t* segment, size_t slice_i
747747
}
748748

749749
// and also for the last one (if not set already) (the last one is needed for coalescing)
750-
mi_slice_t* last = &segment->slices[slice_index + slice_count - 1];
750+
// note: the cast is needed for ubsan since the index can be larger than MI_SLICES_PER_SEGMENT for huge allocations (see #543)
751+
mi_slice_t* last = &((mi_slice_t*)segment->slices)[slice_index + slice_count - 1];
751752
if (last < mi_segment_slices_end(segment) && last >= slice) {
752753
last->slice_offset = (uint32_t)(sizeof(mi_slice_t)*(slice_count-1));
753754
last->slice_count = 0;

0 commit comments

Comments
 (0)