Skip to content

Commit

Permalink
Check bignum multiplication digits overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Nov 8, 2024
1 parent 8fbfdba commit f4e0077
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -5914,6 +5914,8 @@ bigsq(VALUE x)
BDIGIT *xds, *zds;

xn = BIGNUM_LEN(x);
if (ADD_OVERFLOW_LONG_P(2, xn))
rb_raise(rb_eArgError, "square overflow");
zn = 2 * xn;

z = bignew(zn, 1);
Expand Down Expand Up @@ -5942,6 +5944,8 @@ bigmul0(VALUE x, VALUE y)

xn = BIGNUM_LEN(x);
yn = BIGNUM_LEN(y);
if (ADD_OVERFLOW_LONG_P(xn, yn))
rb_raise(rb_eArgError, "multiplication overflow");
zn = xn + yn;

z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));
Expand Down

0 comments on commit f4e0077

Please sign in to comment.