diff options
Diffstat (limited to 'test/psych/test_parser.rb')
| -rw-r--r-- | test/psych/test_parser.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/psych/test_parser.rb b/test/psych/test_parser.rb index c1e0abb89d..4ca4d63d80 100644 --- a/test/psych/test_parser.rb +++ b/test/psych/test_parser.rb @@ -198,6 +198,48 @@ module Psych assert_called :end_stream end + def test_parse_io_returns_more_bytes_than_requested + # An IO-like source whose #read returns more bytes than the size it was + # asked for must not overflow libyaml's read buffer. + io = Object.new + def io.external_encoding; Encoding::UTF_8 end + def io.read len + return nil if @done + @done = true + "--- a\n" + ("#" * (len + (1 << 20))) + end + + # CRuby clamps the over-read and parses; JRuby's parser rejects the + # over-reading IO with an IOError. Either way there is no overflow. + begin + @parser.parse io + rescue IOError + return + end + assert_called :start_stream + assert_called :scalar + assert_called :end_stream + end + + def test_parse_io_returns_more_bytes_than_requested_multibyte + # The over-read is rounded down to a character boundary so a multibyte + # character is never split when the copy is clamped. + io = Object.new + def io.external_encoding; Encoding::UTF_8 end + def io.read len + return nil if @done + @done = true + "--- a\n#" + ("あ" * (len + (1 << 20))) + end + + begin + @parser.parse io + rescue IOError + return + end + assert_called :scalar + end + def test_syntax_error assert_raise(Psych::SyntaxError) do @parser.parse("---\n\"foo\"\n\"bar\"\n") |
