diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-01-08 20:54:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-08 20:54:48 +0900 |
commit | 1cdf8ab07b24ebd16e93621957196e8b1d67f2ba (patch) | |
tree | d5904b2fa13c967749a5e0015b56119a6d5e8645 /bignum.c | |
parent | 89546dce21e1e85f4483a7f9d4049e5608803185 (diff) |
[Bug #19323] Raise `RangeError` instead of integer overflow
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7087
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -4587,11 +4587,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); |