Reproducer for mi_slice_to out of bounds

```
$ CC=clang CXX=clang++ cmake ../../ -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_UBSAN=on
$ make
$ ./mimalloc-test-api
test: malloc-zero...  ok.
test: malloc-nomem1...  mimalloc: error: allocation request is too large (9223372036854775808 bytes)
mimalloc: error: allocation request is too large (9223372036854775808 bytes)
mimalloc: error: unable to allocate memory (9223372036854775808 bytes)
ok.
test: malloc-null...  ok.
test: malloc-large...  .../src/segment.c:750:23: runtime error: index 1089 out of bounds for type 'mi_slice_t [1024]'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior .../src/segment.c:750:23 in
```

See: https://github.com/microsoft/mimalloc/issues/543
Signed-off-by: Christian Heimes <christian@python.org>
This commit is contained in:
Christian Heimes 2022-02-10 16:32:34 +01:00
parent f412df7a2b
commit 9779f26dd1
2 changed files with 6 additions and 1 deletions

View file

@ -91,6 +91,10 @@ int main(void) {
CHECK_BODY("malloc-null",{
mi_free(NULL);
});
CHECK_BODY("malloc-large",{
void *p = mi_malloc(67108872);
mi_free(p);
});
CHECK_BODY("calloc-overflow",{
// use (size_t)&mi_calloc to get some number without triggering compiler warnings
result = (mi_calloc((size_t)&mi_calloc,SIZE_MAX/1000) == NULL);