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

ruby-changes:36081

From: usa <ko1@a...>
Date: Mon, 27 Oct 2014 20:22:22 +0900 (JST)
Subject: [ruby-changes:36081] usa:r48162 (ruby_2_0_0): merge revision(s) 48161:

usa	2014-10-27 20:22:04 +0900 (Mon, 27 Oct 2014)

  New Revision: 48162

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

  Log:
    merge revision(s) 48161:
    
    * lib/rexml/entity.rb: keep the entity size within the limitation.
      reported by Willis Vandevanter <will@s...> and
      patched by nahi.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/lib/rexml/entity.rb
    branches/ruby_2_0_0/test/rexml/test_document.rb
    branches/ruby_2_0_0/test/rexml/test_entity.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 48161)
+++ ruby_2_0_0/ChangeLog	(revision 48162)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Oct 27 20:21:05 2014  NAKAMURA Usaku  <usa@r...>
+
+	* lib/rexml/entity.rb: keep the entity size within the limitation.
+	  reported by Willis Vandevanter <will@s...> and
+	  patched by nahi.
+
 Mon Oct 27 13:26:46 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_method.c (rb_method_entry_make): warn redefinition only for
Index: ruby_2_0_0/lib/rexml/entity.rb
===================================================================
--- ruby_2_0_0/lib/rexml/entity.rb	(revision 48161)
+++ ruby_2_0_0/lib/rexml/entity.rb	(revision 48162)
@@ -138,8 +138,14 @@ module REXML https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/lib/rexml/entity.rb#L138
         matches = @value.scan(PEREFERENCE_RE)
         rv = @value.clone
         if @parent
+          sum = 0
           matches.each do |entity_reference|
             entity_value = @parent.entity( entity_reference[0] )
+            if sum + entity_value.bytesize > Document.entity_expansion_text_limit
+              raise "entity expansion has grown too large"
+            else
+              sum += entity_value.bytesize
+            end
             rv.gsub!( /%#{entity_reference.join};/um, entity_value )
           end
         end
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 48161)
+++ ruby_2_0_0/version.h	(revision 48162)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-10-27"
-#define RUBY_PATCHLEVEL 593
+#define RUBY_PATCHLEVEL 594
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 10
Index: ruby_2_0_0/test/rexml/test_document.rb
===================================================================
--- ruby_2_0_0/test/rexml/test_document.rb	(revision 48161)
+++ ruby_2_0_0/test/rexml/test_document.rb	(revision 48162)
@@ -47,6 +47,20 @@ EOF https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rexml/test_document.rb#L47
 </member>
 EOF
 
+    XML_WITH_NESTED_PARAMETER_ENTITY = <<EOF
+<!DOCTYPE root [
+  <!ENTITY % a "BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.">
+  <!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;">
+  <!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
+  <!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
+  <!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
+  <!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
+  <!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
+ <!ENTITY test "test %g;">
++]>
+<cd></cd>
+EOF
+
   XML_WITH_4_ENTITY_EXPANSION = <<EOF
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE member [
@@ -83,6 +97,19 @@ EOF https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rexml/test_document.rb#L97
     end
   ensure
     REXML::Document.entity_expansion_limit = 10000
+  end
+
+  def test_entity_expansion_limit_for_parameter_entity
+    assert_raise(REXML::ParseException) do
+      REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
+    end
+    REXML::Document.entity_expansion_limit = 100
+    assert_equal(100, REXML::Document.entity_expansion_limit)
+    assert_raise(REXML::ParseException) do
+      REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
+    end
+  ensure
+    REXML::Document.entity_expansion_limit = 10000
   end
 
   def test_tag_in_cdata_with_not_ascii_only_but_ascii8bit_encoding_source
Index: ruby_2_0_0/test/rexml/test_entity.rb
===================================================================
--- ruby_2_0_0/test/rexml/test_entity.rb	(revision 48161)
+++ ruby_2_0_0/test/rexml/test_entity.rb	(revision 48162)
@@ -122,6 +122,22 @@ class EntityTester < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/rexml/test_entity.rb#L122
     end
   end
 
+  def test_entity_string_limit_for_parameter_entity
+    template = '<!DOCTYPE bomb [ <!ENTITY % a "^" > <!ENTITY bomb "$" > ]><root/>'
+    len      = 5120 # 5k per entity
+    template.sub!(/\^/, "B" * len)
+
+    # 10k is OK
+    entities = '%a;' * 2 # 5k entity * 2 = 10k
+    REXML::Document.new(template.sub(/\$/, entities))
+
+    # above 10k explodes
+    entities = '%a;' * 3 # 5k entity * 2 = 15k
+    assert_raises(REXML::ParseException) do
+      REXML::Document.new(template.sub(/\$/, entities))
+    end
+  end
+
   def test_raw
     source = '<!DOCTYPE foo [
 <!ENTITY ent "replace">

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r48161


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

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