mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Check bignum multiplication digits overflow
This commit is contained in:
parent
edb1c8215d
commit
39537e07fe
Notes:
git
2024-11-08 15:08:22 +00:00
1 changed files with 4 additions and 0 deletions
4
bignum.c
4
bignum.c
|
@ -5914,6 +5914,8 @@ bigsq(VALUE x)
|
|||
BDIGIT *xds, *zds;
|
||||
|
||||
xn = BIGNUM_LEN(x);
|
||||
if (MUL_OVERFLOW_LONG_P(2, xn))
|
||||
rb_raise(rb_eArgError, "square overflow");
|
||||
zn = 2 * xn;
|
||||
|
||||
z = bignew(zn, 1);
|
||||
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue