Skip to content

Commit db48c30

Browse files
committed
psych_emitter.c: check tags range
* ext/psych/psych_emitter.c (start_document): should not exceed tags array range. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53079 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent cc03134 commit db48c30

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

ChangeLog

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
Sun Dec 13 18:27:53 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
1+
Sun Dec 13 18:28:52 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* ext/psych/psych_emitter.c (start_document): should not exceed
4+
tags array range.
25

36
* ext/psych/psych_emitter.c (start_document): ensure string before
47
encoding conversion.

ext/psych/psych_emitter.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,18 @@ static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
167167

168168
if(RTEST(tags)) {
169169
long i = 0;
170+
long len;
170171
#ifdef HAVE_RUBY_ENCODING_H
171172
rb_encoding * encoding = rb_utf8_encoding();
172173
#endif
173174

174175
Check_Type(tags, T_ARRAY);
175176

176-
head = xcalloc((size_t)RARRAY_LEN(tags), sizeof(yaml_tag_directive_t));
177+
len = RARRAY_LEN(tags);
178+
head = xcalloc((size_t)len, sizeof(yaml_tag_directive_t));
177179
tail = head;
178180

179-
for(i = 0; i < RARRAY_LEN(tags); i++) {
181+
for(i = 0; i < len && i < RARRAY_LEN(tags); i++) {
180182
VALUE tuple = RARRAY_AREF(tags, i);
181183
VALUE name;
182184
VALUE value;

test/psych/test_emitter.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,20 @@ def test_start_sequence_arg_error
9090
@emitter.start_sequence(nil, nil, true, :foo)
9191
end
9292
end
93+
94+
def test_resizing_tags
95+
tags = []
96+
version = [1,1]
97+
obj = Object.new
98+
obj.instance_variable_set(:@tags, tags)
99+
def obj.to_str
100+
(1..10).map{|x| @tags.push(["AAAA","BBBB"])}
101+
return "x"
102+
end
103+
104+
tags.push([obj, "tag:TALOS"])
105+
@emitter.start_document(version, tags, 0)
106+
assert(true)
107+
end
93108
end
94109
end

0 commit comments

Comments
 (0)