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

ruby-changes:41000

From: nobu <ko1@a...>
Date: Sun, 13 Dec 2015 18:28:58 +0900 (JST)
Subject: [ruby-changes:41000] nobu:r53079 (trunk): psych_emitter.c: check tags range

nobu	2015-12-13 18:28:51 +0900 (Sun, 13 Dec 2015)

  New Revision: 53079

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

  Log:
    psych_emitter.c: check tags range
    
    * ext/psych/psych_emitter.c (start_document): should not exceed
      tags array range.

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/psych_emitter.c
    trunk/test/psych/test_emitter.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53078)
+++ ChangeLog	(revision 53079)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sun Dec 13 18:27:53 2015  Nobuyoshi Nakada  <nobu@r...>
+Sun Dec 13 18:28:52 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/psych/psych_emitter.c (start_document): should not exceed
+	  tags array range.
 
 	* ext/psych/psych_emitter.c (start_document): ensure string before
 	  encoding conversion.
Index: ext/psych/psych_emitter.c
===================================================================
--- ext/psych/psych_emitter.c	(revision 53078)
+++ ext/psych/psych_emitter.c	(revision 53079)
@@ -167,16 +167,18 @@ static VALUE start_document(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L167
 
     if(RTEST(tags)) {
 	long i = 0;
+	long len;
 #ifdef HAVE_RUBY_ENCODING_H
 	rb_encoding * encoding = rb_utf8_encoding();
 #endif
 
 	Check_Type(tags, T_ARRAY);
 
-	head  = xcalloc((size_t)RARRAY_LEN(tags), sizeof(yaml_tag_directive_t));
+	len = RARRAY_LEN(tags);
+	head  = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
 	tail  = head;
 
-	for(i = 0; i < RARRAY_LEN(tags); i++) {
+	for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
 	    VALUE tuple = RARRAY_AREF(tags, i);
 	    VALUE name;
 	    VALUE value;
Index: test/psych/test_emitter.rb
===================================================================
--- test/psych/test_emitter.rb	(revision 53078)
+++ test/psych/test_emitter.rb	(revision 53079)
@@ -90,5 +90,20 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_emitter.rb#L90
         @emitter.start_sequence(nil, nil, true, :foo)
       end
     end
+
+    def test_resizing_tags
+      tags = []
+      version = [1,1]
+      obj = Object.new
+      obj.instance_variable_set(:@tags, tags)
+      def obj.to_str
+        (1..10).map{|x| @tags.push(["AAAA","BBBB"])}
+        return "x"
+      end
+
+      tags.push([obj, "tag:TALOS"])
+      @emitter.start_document(version, tags, 0)
+      assert(true)
+    end
   end
 end

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

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