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

ruby-changes:60012

From: Nobuyoshi <ko1@a...>
Date: Wed, 12 Feb 2020 15:07:41 +0900 (JST)
Subject: [ruby-changes:60012] 52cdf400ef (master): Workaround of instance variable on hidden object

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

From 52cdf400efaecc0f5e1d1f70f22dc45212e03c4c Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 11 Feb 2020 11:28:31 +0900
Subject: Workaround of instance variable on hidden object

Since 9d9aea7fe50f6340829faa105d9ffe08ebaee658, generic instance
variables need `iv_index_tbl` in the object's class.  As hidden
objects, however, have no class, access to the variables causes a
segfault.  Get rid of that segfault by raising an exception, for
the time being.

diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb
index 282ac6b..6d0665a 100644
--- a/test/ruby/test_encoding.rb
+++ b/test/ruby/test_encoding.rb
@@ -65,6 +65,18 @@ class TestEncoding < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_encoding.rb#L65
     END;
   end
 
+  def test_extra_encoding
+    assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+    begin;
+      200.times {|i|
+        Encoding::UTF_8.replicate("dummy#{i}")
+      }
+      e = Encoding.list.last
+      format = "%d".force_encoding(e)
+      assert_raise(TypeError) {format % 0}
+    end;
+  end
+
   def test_dummy_p
     assert_equal(true, Encoding::ISO_2022_JP.dummy?)
     assert_equal(false, Encoding::UTF_8.dummy?)
diff --git a/variable.c b/variable.c
index 646d60d..2dba766 100644
--- a/variable.c
+++ b/variable.c
@@ -1134,9 +1134,12 @@ static st_table * https://github.com/ruby/ruby/blob/trunk/variable.c#L1134
 iv_index_tbl_make(VALUE obj)
 {
     VALUE klass = rb_obj_class(obj);
-    st_table *iv_index_tbl = RCLASS_IV_INDEX_TBL(klass);
+    st_table *iv_index_tbl;
 
-    if (!iv_index_tbl) {
+    if (!klass) {
+        rb_raise(rb_eTypeError, "hidden object cannot have instance variables");
+    }
+    if (!(iv_index_tbl = RCLASS_IV_INDEX_TBL(klass))) {
 	iv_index_tbl = RCLASS_IV_INDEX_TBL(klass) = st_init_numtable();
     }
 
-- 
cgit v0.10.2


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

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