From a4ce63abc598f93cca66d59fd196a7293b9566fb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 20 Jul 2022 14:40:12 +0900 Subject: [PATCH] bigint.c (mpz_sizeinbase): check zero length bigint. --- mrbgems/mruby-bigint/core/bigint.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index b8dc4487b..d984c2fdc 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -617,7 +617,10 @@ mpz_sizeinbase(mpz_t *x, int base) { int i,j; size_t bits = digits(x) * DIGITBITS; + mrb_assert(2 <= base && base <= 36); + + if (x->sz == 0) return 0; for (j=0,i=1; i<=base; i*=2,j++) ; return (int)((bits)/(j-1)+1);