Skip to content

Commit 39537e0

Browse files
committed
Check bignum multiplication digits overflow
1 parent edb1c82 commit 39537e0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

bignum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5914,6 +5914,8 @@ bigsq(VALUE x)
59145914
BDIGIT *xds, *zds;
59155915

59165916
xn = BIGNUM_LEN(x);
5917+
if (MUL_OVERFLOW_LONG_P(2, xn))
5918+
rb_raise(rb_eArgError, "square overflow");
59175919
zn = 2 * xn;
59185920

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

59435945
xn = BIGNUM_LEN(x);
59445946
yn = BIGNUM_LEN(y);
5947+
if (ADD_OVERFLOW_LONG_P(xn, yn))
5948+
rb_raise(rb_eArgError, "multiplication overflow");
59455949
zn = xn + yn;
59465950

59475951
z = bignew(zn, BIGNUM_SIGN(x)==BIGNUM_SIGN(y));

0 commit comments

Comments
 (0)