diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-11-08 19:04:07 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-11-09 00:08:03 +0900 |
commit | 39537e07fe606b8b05ce2a07368f1341fe96db5d (patch) | |
tree | 32fa9496a1d0da8dc7dd04867f6e0a55a863d769 /bignum.c | |
parent | edb1c8215d849726adb8011a7dff9d38a73baa61 (diff) |
Check bignum multiplication digits overflow
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12034
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -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)); |