Skip to content

Commit

Permalink
raise an exception when bogus values are returned from an IO object
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 16, 2010
1 parent c4fbedc commit 26fe5a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/psych/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ static int io_reader(void * data, unsigned char *buf, size_t size, size_t *read)
*read = 0;

if(! NIL_P(string)) {
void * str = (void *)StringValuePtr(string);
*read = (size_t)RSTRING_LEN(string);
memcpy(buf, StringValuePtr(string), *read);
memcpy(buf, str, *read);
}

return 1;
Expand Down
9 changes: 9 additions & 0 deletions test/psych/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def setup
@parser = Psych::Parser.new EventCatcher.new
end

def test_bogus_io
o = Object.new
def o.read len; self end

assert_raises(TypeError) do
@parser.parse o
end
end

def test_parse_io
@parser.parse StringIO.new("--- a")
assert_called :start_stream
Expand Down

0 comments on commit 26fe5a3

Please sign in to comment.