Clang-asan: stack-buffer-overflow in memcpy

You can see the problem here, https://www.stats.ox.ac.uk/pub/bdr/memtests/clang-ASAN/rswipl/00check.log

I can circumvent this issue by linking to libgmp instead of libbf (license is not an issue), but I wonder if this a problem at all, since a bit below, the text says “HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork”.

Unfortunately, I cannot provide anything more than reporting this issue. Without ASAN, the bf_trig_alloc test runs fine, and one can query plunit_bigint:exponential_div(3,16000,R) without obvious problems.

1 Like

This reproduces. The fact that it does not occur with GMP is probably just luck. The same, apparently broken, code is used both for GMP and LibBF, using a small stack memory buffer so we can avoid trashing malloc() for the common rather small bigint operations.

1 Like

Good catch. Fixed with 64ef800a1bd8e4443755c7e9a0a0db6766f1b8bf

1 Like

Three UBSAN errors at libbf/mersenne-twister.c.

I asked the author if this is expected (since in that case, one could simply disable the check for the particular function).