summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-29 17:35:11 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-29 17:35:11 +0000
commitd45010b150b552c81b00ba62d69148bbba8b5a92 (patch)
tree92c8d777e3aeff6624fa7a4b01da74899470720f
parent2d0fc0ac04304a0a5c3ff232bedd053106cab93c (diff)
downloadruby-d45010b150b552c81b00ba62d69148bbba8b5a92.tar.gz
ruby-d45010b150b552c81b00ba62d69148bbba8b5a92.tar.xz
ruby-d45010b150b552c81b00ba62d69148bbba8b5a92.zip
* bignum.c (big2str_find_n1): check integer overflow.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--bignum.c3
-rw-r--r--test/ruby/test_bignum.rb9
3 files changed, 16 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d2f51d55..3bb1a63e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Mar 1 02:35:08 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * bignum.c (big2str_find_n1): check integer overflow.
+
Sat Mar 1 00:29:07 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* encoding.c (rb_enc_dummy_p): bootstrap encodings can not be dummy.
diff --git a/bignum.c b/bignum.c
index 773cba30b..649b258c5 100644
--- a/bignum.c
+++ b/bignum.c
@@ -829,6 +829,9 @@ big2str_find_n1(VALUE x, int base)
else if (BIGZEROP(x)) {
return 0;
}
+ else if (RBIGNUM_LEN(x) >= LONG_MAX/BITSPERDIG) {
+ rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
+ }
else {
bits = BITSPERDIG*RBIGNUM_LEN(x);
}
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 2d9008ecc..be33e2f5a 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -377,4 +377,13 @@ class TestBignum < Test::Unit::TestCase
def test_interrupt
assert(interrupt { (65536 ** 65536).to_s })
end
+
+ def test_too_big_to_s
+ i = 32
+ while (big = 2**(i-1)-1).is_a?(Fixnum)
+ i *= 2
+ end
+ e = assert_raise(RangeError) {(1 << big).to_s}
+ assert_match(/too big to convert/, e.message)
+ end
end