mimalloc/include
Vedant Ravindra Dhoke 7ec98efee7
Fix: Prevent out-of-bounds read in mi_ctz_generic32 and mi_clz_generic32
This patch ensures that both mi_ctz_generic32 and mi_clz_generic32 perform safe indexing into the de Bruijn lookup tables by masking the computed index with `& 31`.

On platforms where unsigned long is 64-bit, the result of the de Bruijn multiplication and shift could exceed the valid index range (0–31), leading to an out-of-bounds read.

This change applies a bitwise AND mask to the final index:
- `mi_ctz_generic32`: debruijn[(((x & -(int32_t)x) * 0x077CB531U) >> 27) & 31]
- `mi_clz_generic32`: debruijn[((x * 0x07C4ACDDU) >> 27) & 31]

This matches the fix applied in python/cpython#134070 to its integrated mimalloc copy.

Fixes: python/cpython#134070
2025-05-17 15:52:26 -04:00
..
mimalloc Fix: Prevent out-of-bounds read in mi_ctz_generic32 and mi_clz_generic32 2025-05-17 15:52:26 -04:00
mimalloc-new-delete.h Fix whitespace 2022-12-03 00:24:20 +01:00
mimalloc-override.h bump cmake required version to 3.18 and detect libatomic more reliably, see pr #898 2024-05-19 13:25:31 -07:00
mimalloc-stats.h collect every N generic calls 2025-03-02 17:06:25 -08:00
mimalloc.h bump version to 2.2.3 for further development 2025-03-06 21:04:32 -08:00