summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-01-08 20:54:48 +0900
committerGitHub <noreply@github.com>2023-01-08 20:54:48 +0900
commit1cdf8ab07b24ebd16e93621957196e8b1d67f2ba (patch)
treed5904b2fa13c967749a5e0015b56119a6d5e8645 /bignum.c
parent89546dce21e1e85f4483a7f9d4049e5608803185 (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.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/bignum.c b/bignum.c
index 4f8349dd17..a1a659db09 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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);