summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-27 11:23:17 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-27 11:23:17 +0000
commitd86ba46a65734423c05cb399c61f096db4f82712 (patch)
tree8269cb0ca105be1a161ee5ed96a2ab1859cf1dd5
parenteca3835c65f6e63b92dd5387257322323ab43563 (diff)
merge revision(s) r48161:
* 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_1@48163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--lib/rexml/entity.rb6
-rw-r--r--test/rexml/test_document.rb27
-rw-r--r--test/rexml/test_entity.rb16
-rw-r--r--version.h6
5 files changed, 58 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index ba03421dea..19dbbd025e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Oct 27 20:20:14 2014 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * lib/rexml/entity.rb: keep the entity size within the limitation.
+ reported by Willis Vandevanter <will@silentrobots.com> and
+ patched by nahi.
+
Sun Oct 26 03:31:46 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_method.c (rb_method_entry_make): warn redefinition only for
diff --git a/lib/rexml/entity.rb b/lib/rexml/entity.rb
index 39f3900075..f447202394 100644
--- a/lib/rexml/entity.rb
+++ b/lib/rexml/entity.rb
@@ -138,8 +138,14 @@ module REXML
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 > Security.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
diff --git a/test/rexml/test_document.rb b/test/rexml/test_document.rb
index cec9452373..efdcf66b82 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::Security.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::Security.entity_expansion_limit = 100
+ assert_equal(100, REXML::Security.entity_expansion_limit)
+ assert_raise(REXML::ParseException) do
+ REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
+ end
+ ensure
+ REXML::Security.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 7b9f39495f..ddb6f4565d 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">
diff --git a/version.h b/version.h
index b6f5a953ef..794e0d672c 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.1.4"
-#define RUBY_RELEASE_DATE "2014-10-26"
-#define RUBY_PATCHLEVEL 264
+#define RUBY_RELEASE_DATE "2014-10-27"
+#define RUBY_PATCHLEVEL 265
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 10
-#define RUBY_RELEASE_DAY 26
+#define RUBY_RELEASE_DAY 27
#include "ruby/version.h"