[前][次][番号順一覧][スレッド一覧]

ruby-changes:4156

From: ko1@a...
Date: Sat, 1 Mar 2008 02:35:35 +0900 (JST)
Subject: [ruby-changes:4156] nobu - Ruby:r15646 (trunk, ruby_1_8): * bignum.c (big2str_find_n1): check integer overflow.

nobu	2008-03-01 02:35:11 +0900 (Sat, 01 Mar 2008)

  New Revision: 15646

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/bignum.c
    branches/ruby_1_8/test/ruby/test_bignum.rb
    branches/ruby_1_8/version.h
    trunk/ChangeLog
    trunk/bignum.c
    trunk/test/ruby/test_bignum.rb

  Log:
    * bignum.c (big2str_find_n1): check integer overflow.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_bignum.rb?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/ruby/test_bignum.rb?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bignum.c?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/bignum.c?r1=15646&r2=15645&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/version.h?r1=15646&r2=15645&diff_format=u

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15645)
+++ ChangeLog	(revision 15646)
@@ -1,3 +1,7 @@
+Sat Mar  1 02:35:08 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* bignum.c (big2str_find_n1): check integer overflow.
+
 Sat Mar  1 00:29:07 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* encoding.c (rb_enc_dummy_p): bootstrap encodings can not be dummy.
Index: bignum.c
===================================================================
--- bignum.c	(revision 15645)
+++ bignum.c	(revision 15646)
@@ -829,6 +829,9 @@
     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);
     }
Index: test/ruby/test_bignum.rb
===================================================================
--- test/ruby/test_bignum.rb	(revision 15645)
+++ test/ruby/test_bignum.rb	(revision 15646)
@@ -377,4 +377,13 @@
   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
Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 15645)
+++ ruby_1_8/ChangeLog	(revision 15646)
@@ -1,3 +1,7 @@
+Sat Mar  1 02:35:08 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* bignum.c (big2str_find_n1): check integer overflow.
+
 Tue Feb 26 16:06:00 2008  Technorama Ltd.  <oss-ruby@t...>
 
 	* ext/openssl/ossl_pkey_{ec,dh,dsa,rsa}.c: Remove useless warnings.
Index: ruby_1_8/version.h
===================================================================
--- ruby_1_8/version.h	(revision 15645)
+++ ruby_1_8/version.h	(revision 15646)
@@ -1,15 +1,15 @@
 #define RUBY_VERSION "1.8.6"
-#define RUBY_RELEASE_DATE "2008-02-26"
+#define RUBY_RELEASE_DATE "2008-03-01"
 #define RUBY_VERSION_CODE 186
-#define RUBY_RELEASE_CODE 20080226
+#define RUBY_RELEASE_CODE 20080301
 #define RUBY_PATCHLEVEL 5000
 
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 8
 #define RUBY_VERSION_TEENY 6
 #define RUBY_RELEASE_YEAR 2008
-#define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 26
+#define RUBY_RELEASE_MONTH 3
+#define RUBY_RELEASE_DAY 1
 
 #ifdef RUBY_EXTERN
 RUBY_EXTERN const char ruby_version[];
Index: ruby_1_8/bignum.c
===================================================================
--- ruby_1_8/bignum.c	(revision 15645)
+++ ruby_1_8/bignum.c	(revision 15646)
@@ -676,6 +676,9 @@
     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;
Index: ruby_1_8/test/ruby/test_bignum.rb
===================================================================
--- ruby_1_8/test/ruby/test_bignum.rb	(revision 15645)
+++ ruby_1_8/test/ruby/test_bignum.rb	(revision 15646)
@@ -95,4 +95,13 @@
     assert_equal("1777777777777777777777" ,18446744073709551615.to_s(8))
     assert_equal("-1777777777777777777777" ,-18446744073709551615.to_s(8))
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]