summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 10:54:01 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-15 10:54:01 +0000
commitc71b916f37c5dc0c0202b4410af2c3dc1c740bb9 (patch)
tree98c38f4178c5e3badce86f6bb073479d9889de51
parent6d2a37a0e74ade72c0750c5c8446a654469b2db1 (diff)
merge revision(s) 15645:15647:
* bignum.c (big2str_find_n1): check integer overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_5@17196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--bignum.c3
-rw-r--r--test/ruby/test_bignum.rb8
-rw-r--r--version.h2
4 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 2922c07..6bb10d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Jun 15 19:53:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * bignum.c (big2str_find_n1): check integer overflow.
+
Sun Jun 15 19:51:37 2008 Tanaka Akira <akr@fsij.org>
* gc.c (STACK_LENGTH) [SPARC] : 0x80 offset removed. [ruby-dev:33857]
diff --git a/bignum.c b/bignum.c
index cf7649c..80ab1c9 100644
--- a/bignum.c
+++ b/bignum.c
@@ -636,6 +636,9 @@ rb_big2str(x, base)
if (BIGZEROP(x)) {
return rb_str_new2("0");
}
+ if (i >= LONG_MAX/SIZEOF_BDIGITS/CHAR_BIT) {
+ rb_raise(rb_eRangeError, "bignum too big to convert into `string'");
+ }
j = SIZEOF_BDIGITS*CHAR_BIT*i;
switch (base) {
case 2: break;
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index c238337..e070a9c 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -84,4 +84,12 @@ class TestBignum < Test::Unit::TestCase
shift_test(-4518325415524767873)
shift_test(-0xfffffffffffffffff)
end
+
+ def test_too_big_to_s
+ if (big = 2**31-1).is_a?(Fixnum)
+ return
+ end
+ e = assert_raise(RangeError) {(1 << big).to_s}
+ assert_match(/too big to convert/, e.message)
+ end
end
diff --git a/version.h b/version.h
index 9a31e9a..96dcbc1 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2008-06-15"
#define RUBY_VERSION_CODE 185
#define RUBY_RELEASE_CODE 20080615
-#define RUBY_PATCHLEVEL 182
+#define RUBY_PATCHLEVEL 183
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8