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

ruby-changes:59258

From: nagachika <ko1@a...>
Date: Sun, 15 Dec 2019 17:47:10 +0900 (JST)
Subject: [ruby-changes:59258] fd3c731a31 (ruby_2_6): merge revision(s) ff41663403d3eb76d95f465cb94e14d2faaa04d1: [Backport #16354]

https://git.ruby-lang.org/ruby.git/commit/?id=fd3c731a31

From fd3c731a31bfed559af8bd9e4ca394632bedf05a Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sun, 15 Dec 2019 08:28:52 +0000
Subject: merge revision(s) ff41663403d3eb76d95f465cb94e14d2faaa04d1: [Backport
 #16354]

	Fix memory corruption in Enumerable#reverse_each [ruby-dev:50867]
	 [Bug #16354]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/enum.c b/enum.c
index a739d33..7b4d4b4 100644
--- a/enum.c
+++ b/enum.c
@@ -2337,14 +2337,20 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/enum.c#L2337
 enum_reverse_each(int argc, VALUE *argv, VALUE obj)
 {
     VALUE ary;
-    long i;
+    long len;
 
     RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size);
 
     ary = enum_to_a(argc, argv, obj);
 
-    for (i = RARRAY_LEN(ary); --i >= 0; ) {
-	rb_yield(RARRAY_AREF(ary, i));
+    len = RARRAY_LEN(ary);
+    while (len--) {
+        long nlen;
+        rb_yield(RARRAY_AREF(ary, len));
+        nlen = RARRAY_LEN(ary);
+        if (nlen < len) {
+            len = nlen;
+        }
     }
 
     return obj;
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index c56e280e..568fa0e 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -730,6 +730,19 @@ class TestEnumerable < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L730
     assert_equal([2,1,3,2,1], @obj.reverse_each.to_a)
   end
 
+  def test_reverse_each_memory_corruption
+    bug16354 = '[ruby-dev:50867]'
+    assert_normal_exit %q{
+      size = 1000
+      (0...size).reverse_each do |i|
+        i.inspect
+        ObjectSpace.each_object(Array) do |a|
+          a.clear if a.length == size
+        end
+      end
+    }, bug16354
+  end
+
   def test_chunk
     e = [].chunk {|elt| true }
     assert_equal([], e.to_a)
diff --git a/version.h b/version.h
index 1ff90df..d8a0218 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.6"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 122
+#define RUBY_PATCHLEVEL 123
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 12
-- 
cgit v0.10.2


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

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