mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-bigint: add safety margin to karatsuba scratch allocation
prevents buffer overrun in karatsuba multiplication scratch space due to rounding errors in recursive partitioning. empirically determined 8-limb margin fixes valgrind-detected overrun with large exponentiations. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1104,6 +1104,8 @@ mpz_mul(mpz_ctx_t *ctx, mpz_t *ww, mpz_t *u, mpz_t *v)
|
||||
mpz_realloc(ctx, ww, result_size);
|
||||
|
||||
size_t scratch_size = karatsuba_scratch_size(u->sz, v->sz);
|
||||
/* Add safety margin to account for rounding in recursive partitioning */
|
||||
scratch_size += 8;
|
||||
size_t pool_state = pool_save(ctx);
|
||||
mp_limb *scratch = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user