diff options
author | U.Nakamura <usa@ruby-lang.org> | 2023-06-19 20:21:40 +0900 |
---|---|---|
committer | U.Nakamura <usa@ruby-lang.org> | 2023-06-19 20:21:40 +0900 |
commit | 344249674f7a7835445a44695664897fa4b83f00 (patch) | |
tree | 8b01aa0583249abea8b50ad8093ca507a0059a71 /bignum.c | |
parent | e031f2b4c7be8854f424cfc692f7ce27213abdd2 (diff) |
merge revision(s) 1cdf8ab07b24ebd16e93621957196e8b1d67f2ba: [Backport #19323]
[Bug #19323] Raise `RangeError` instead of integer overflow
---
bignum.c | 5 ++++-
test/ruby/test_integer.rb | 18 ++++++++----------
2 files changed, 12 insertions(+), 11 deletions(-)
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -4569,11 +4569,14 @@ big_shift3(VALUE x, int lshift_p, size_t shift_numdigits, int shift_numbits) if (lshift_p) { if (LONG_MAX < shift_numdigits) { - rb_raise(rb_eArgError, "too big number"); + too_big: + rb_raise(rb_eRangeError, "shift width too big"); } s1 = shift_numdigits; s2 = shift_numbits; + if ((size_t)s1 != shift_numdigits) goto too_big; xn = BIGNUM_LEN(x); + if (LONG_MAX/SIZEOF_BDIGIT <= xn+s1) goto too_big; z = bignew(xn+s1+1, BIGNUM_SIGN(x)); zds = BDIGITS(z); BDIGITS_ZERO(zds, s1); |