Skip to content

Commit 31d25ce

Browse files
committed
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
1 parent d841eef commit 31d25ce

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Mon Oct 27 20:20:14 2014 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* lib/rexml/entity.rb: keep the entity size within the limitation.
4+
reported by Willis Vandevanter <will@silentrobots.com> and
5+
patched by nahi.
6+
17
Sun Oct 26 03:31:46 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
28

39
* vm_method.c (rb_method_entry_make): warn redefinition only for

lib/rexml/entity.rb

+6
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,14 @@ def value
138138
matches = @value.scan(PEREFERENCE_RE)
139139
rv = @value.clone
140140
if @parent
141+
sum = 0
141142
matches.each do |entity_reference|
142143
entity_value = @parent.entity( entity_reference[0] )
144+
if sum + entity_value.bytesize > Security.entity_expansion_text_limit
145+
raise "entity expansion has grown too large"
146+
else
147+
sum += entity_value.bytesize
148+
end
143149
rv.gsub!( /%#{entity_reference.join};/um, entity_value )
144150
end
145151
end

test/rexml/test_document.rb

+27
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ def test_new
4545
<member>
4646
&a;
4747
</member>
48+
EOF
49+
50+
XML_WITH_NESTED_PARAMETER_ENTITY = <<EOF
51+
<!DOCTYPE root [
52+
<!ENTITY % a "BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.BOOM.">
53+
<!ENTITY % b "%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;%a;">
54+
<!ENTITY % c "%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;%b;">
55+
<!ENTITY % d "%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;%c;">
56+
<!ENTITY % e "%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;">
57+
<!ENTITY % f "%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;%e;">
58+
<!ENTITY % g "%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;%f;">
59+
<!ENTITY test "test %g;">
60+
]>
61+
<cd></cd>
4862
EOF
4963

5064
XML_WITH_4_ENTITY_EXPANSION = <<EOF
@@ -85,6 +99,19 @@ def test_entity_expansion_limit
8599
REXML::Security.entity_expansion_limit = 10000
86100
end
87101

102+
def test_entity_expansion_limit_for_parameter_entity
103+
assert_raise(REXML::ParseException) do
104+
REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
105+
end
106+
REXML::Security.entity_expansion_limit = 100
107+
assert_equal(100, REXML::Security.entity_expansion_limit)
108+
assert_raise(REXML::ParseException) do
109+
REXML::Document.new(XML_WITH_NESTED_PARAMETER_ENTITY)
110+
end
111+
ensure
112+
REXML::Security.entity_expansion_limit = 10000
113+
end
114+
88115
def test_tag_in_cdata_with_not_ascii_only_but_ascii8bit_encoding_source
89116
tag = "<b>...</b>"
90117
message = "こんにちは、世界!" # Hello world! in Japanese

test/rexml/test_entity.rb

+16
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ def test_entity_string_limit
122122
end
123123
end
124124

125+
def test_entity_string_limit_for_parameter_entity
126+
template = '<!DOCTYPE bomb [ <!ENTITY % a "^" > <!ENTITY bomb "$" > ]><root/>'
127+
len = 5120 # 5k per entity
128+
template.sub!(/\^/, "B" * len)
129+
130+
# 10k is OK
131+
entities = '%a;' * 2 # 5k entity * 2 = 10k
132+
REXML::Document.new(template.sub(/\$/, entities))
133+
134+
# above 10k explodes
135+
entities = '%a;' * 3 # 5k entity * 2 = 15k
136+
assert_raises(REXML::ParseException) do
137+
REXML::Document.new(template.sub(/\$/, entities))
138+
end
139+
end
140+
125141
def test_raw
126142
source = '<!DOCTYPE foo [
127143
<!ENTITY ent "replace">

version.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.4"
2-
#define RUBY_RELEASE_DATE "2014-10-26"
3-
#define RUBY_PATCHLEVEL 264
2+
#define RUBY_RELEASE_DATE "2014-10-27"
3+
#define RUBY_PATCHLEVEL 265
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 10
7-
#define RUBY_RELEASE_DAY 26
7+
#define RUBY_RELEASE_DAY 27
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)