diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-27 11:22:04 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-10-27 11:22:04 +0000 |
commit | 61ff012d26bb77962dc7d7f7e04d73f8ae54c676 (patch) | |
tree | 207e8ba7286c8a2f25e4d62b8f3d86240e197228 /test | |
parent | 2c31816f1abd48cadda2e91262e0b30913fe1694 (diff) |
merge revision(s) 48161:
* lib/rexml/entity.rb: keep the entity size within the limitation.
reported by Willis Vandevanter <will@silentrobots.com> and
patched by nahi.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@48162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/rexml/test_document.rb | 27 | ||||
-rw-r--r-- | test/rexml/test_entity.rb | 16 |
2 files changed, 43 insertions, 0 deletions
diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb index 3ef584c290..38f502f14d 100644 --- a/test/rexml/test_document.rb +++ b/test/rexml/test_document.rb @@ -47,6 +47,20 @@ EOF </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 [ @@ -85,6 +99,19 @@ EOF 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 tag = "<b>...</b>" message = "こんにちは、世界!" # Hello world! in Japanese diff --git a/test/rexml/test_entity.rb b/test/rexml/test_entity.rb index 5900fac7a8..93c4c838f6 100644 --- a/test/rexml/test_entity.rb +++ b/test/rexml/test_entity.rb @@ -122,6 +122,22 @@ class EntityTester < Test::Unit::TestCase 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"> |