Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem "net-smtp"
gem 'csv'
gem 'ostruct'
gem 'pstore'
gem "timeout"

group :minitest do
gem "minitest"
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ DEPENDENCIES
steep!
tempfile
test-unit
timeout

BUNDLED WITH
4.0.1
6 changes: 5 additions & 1 deletion src/lexstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ bool rbs_next_char(rbs_lexer_t *lexer, unsigned int *codepoint, size_t *byte_len

*byte_len = lexer->encoding->char_width((const uint8_t *) start, (ptrdiff_t) (lexer->string.end - start));

if (*byte_len == 1) {
if (*byte_len == 0) {
// Avoid infinite loop on invalid bytes.
*byte_len = 1;
*codepoint = (unsigned int) (unsigned char) *start;
} else if (*byte_len == 1) {
*codepoint = (unsigned int) *start;
} else {
*codepoint = 12523; // Dummy data for "ル" from "ルビー" (Ruby) in Unicode
Expand Down
19 changes: 19 additions & 0 deletions test/rbs/parser_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test_helper"
require "timeout"

class RBS::ParserTest < Test::Unit::TestCase
def buffer(source)
Expand Down Expand Up @@ -1028,4 +1029,22 @@ class Foo[T < Integer] < Bar # Comment
assert_equal [:tTRIVIA, "\n", 56...57], tokens.shift.then { |t| [t[0], t[1].source, t[1].range] }
assert_equal [:pEOF, '', 57...57], tokens.shift.then { |t| [t[0], t[1].source, t[1].range] }
end

def test_invalid_utf8_byte_in_comment_does_not_hang
# Regression: invalid UTF-8 byte in a comment used to loop forever in the lexer.
source = "# \xC2".dup.force_encoding(Encoding::UTF_8)
Timeout.timeout(5) do
RBS::Parser._parse_signature(buffer(source), 0, source.bytesize)
end
end

def test_invalid_utf8_byte_at_top_level_raises
# Regression: invalid UTF-8 byte at top level used to trip RBS_ASSERT in the C extension.
source = "\xFF".dup.force_encoding(Encoding::UTF_8)
Timeout.timeout(5) do
assert_raises(RBS::ParsingError) do
RBS::Parser._parse_signature(buffer(source), 0, source.bytesize)
end
end
end
end
Loading