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

ruby-changes:54664

From: nagachika <ko1@a...>
Date: Sun, 20 Jan 2019 18:18:06 +0900 (JST)
Subject: [ruby-changes:54664] nagachika:r66880 (ruby_2_5): merge revision(s) 63334: [Backport #14729]

nagachika	2019-01-20 18:17:59 +0900 (Sun, 20 Jan 2019)

  New Revision: 66880

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66880

  Log:
    merge revision(s) 63334: [Backport #14729]
    
    object.c: raise on long invalid float string
    
    * object.c (rb_cstr_to_dbl_raise): check long invalid float
      string more precisely when truncating insignificant part.
      [ruby-core:86800] [Bug #14729]

  Modified directories:
    branches/ruby_2_5/
  Modified files:
    branches/ruby_2_5/object.c
    branches/ruby_2_5/test/ruby/test_float.rb
    branches/ruby_2_5/version.h
Index: ruby_2_5/object.c
===================================================================
--- ruby_2_5/object.c	(revision 66879)
+++ ruby_2_5/object.c	(revision 66880)
@@ -3239,29 +3239,53 @@ rb_cstr_to_dbl(const char *p, int badche https://github.com/ruby/ruby/blob/trunk/ruby_2_5/object.c#L3239
 	return d;
     }
     if (*end) {
-	char buf[DBL_DIG * 4 + 10];
-	char *n = buf;
-	char *const init_e = buf + DBL_DIG * 4;
-	char *e = init_e;
-	char prev = 0;
+        char buf[DBL_DIG * 4 + 10];
+        char *n = buf;
+        char *const init_e = buf + DBL_DIG * 4;
+        char *e = init_e;
+        char prev = 0;
+        int dot_seen = FALSE;
 
-	while (p < end && n < e) prev = *n++ = *p++;
-	while (*p) {
-	    if (*p == '_') {
-		/* remove an underscore between digits */
-		if (n == buf || !ISDIGIT(prev) || (++p, !ISDIGIT(*p))) {
-		    if (badcheck) goto bad;
-		    break;
-		}
-	    }
-	    prev = *p++;
-	    if (e == init_e && (*p == 'e' || *p == 'E')) {
-	        e = buf + sizeof(buf) - 1;
-	    }
-	    if (n < e) *n++ = prev;
-	}
-	*n = '\0';
-	p = buf;
+        switch (*p) {case '+': case '-': prev = *n++ = *p++;}
+        if (*p == '0') {
+            prev = *n++ = '0';
+            while (*++p == '0');
+        }
+        while (p < end && n < e) prev = *n++ = *p++;
+        while (*p) {
+            if (*p == '_') {
+                /* remove an underscore between digits */
+                if (n == buf || !ISDIGIT(prev) || (++p, !ISDIGIT(*p))) {
+                    if (badcheck) goto bad;
+                    break;
+                }
+            }
+            prev = *p++;
+            if (e == init_e && (prev == 'e' || prev == 'E' || prev == 'p' || prev == 'P')) {
+                e = buf + sizeof(buf) - 1;
+                *n++ = prev;
+                switch (*p) {case '+': case '-': prev = *n++ = *p++;}
+                if (*p == '0') {
+                    prev = *n++ = '0';
+                    while (*++p == '0');
+                }
+                continue;
+            }
+            else if (ISSPACE(prev)) {
+                while (ISSPACE(*p)) ++p;
+                if (*p) {
+                    if (badcheck) goto bad;
+                    break;
+                }
+            }
+            else if (prev == '.' ? dot_seen++ : !ISDIGIT(prev)) {
+                if (badcheck) goto bad;
+                break;
+            }
+            if (n < e) *n++ = prev;
+        }
+        *n = '\0';
+        p = buf;
 
 	if (!badcheck && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
 	    return 0.0;
Index: ruby_2_5/version.h
===================================================================
--- ruby_2_5/version.h	(revision 66879)
+++ ruby_2_5/version.h	(revision 66880)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1
 #define RUBY_VERSION "2.5.4"
 #define RUBY_RELEASE_DATE "2019-01-20"
-#define RUBY_PATCHLEVEL 135
+#define RUBY_PATCHLEVEL 136
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 1
Index: ruby_2_5/test/ruby/test_float.rb
===================================================================
--- ruby_2_5/test/ruby/test_float.rb	(revision 66879)
+++ ruby_2_5/test/ruby/test_float.rb	(revision 66880)
@@ -165,6 +165,12 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_float.rb#L165
     end
 
     assert_equal(1.0e10, Float("1.0_"+"00000"*Float::DIG+"e10"))
+
+    z = "0" * (Float::DIG * 4 + 10)
+    all_assertions_foreach("long invalid string", "1.0", "1.0e", "1.0e-", "1.0e+") do |n|
+      assert_raise(ArgumentError, n += z + "A") {Float(n)}
+      assert_raise(ArgumentError, n += z + ".0") {Float(n)}
+    end
   end
 
   def test_divmod
Index: ruby_2_5
===================================================================
--- ruby_2_5	(revision 66879)
+++ ruby_2_5	(revision 66880)

Property changes on: ruby_2_5
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r63334

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

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