microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
9.74k stars 791 forks source link

`slice_count` overflow for very large allocations #876

Closed colesbury closed 2 months ago

colesbury commented 2 months ago

This was seen in https://github.com/python/cpython/issues/117755 on s390x (Linux on IBMz) for an allocation of 0x7fffffffffffffff bytes:

https://github.com/microsoft/mimalloc/blob/f199b888b47f77261aac9b63b612e77ff3fbd880/src/segment.c#L617-L618

The mi_segment_os_alloc is successful (possibly due to overcommit), but then the slice_count is truncated, which leads to either an assertion error (in debug builds) or floating point error due to a divide by zero.

vstinner commented 2 months ago

I proposed a fix: https://github.com/microsoft/mimalloc/pull/877

daanx commented 2 months ago

Ah, that is a terrible bug but I just merged a fix. I am going to do a fresh release tag soon. Thanks so much!