Skip to content

Commit

Permalink
Fix parsing incomplete unicode escape "\uaaa"
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Jan 20, 2025
1 parent f8817fe commit 86c0d4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ static VALUE json_string_unescape(JSON_ParserState *state, const char *string, c
unescape = (char *) "\f";
break;
case 'u':
if (pe > stringEnd - 4) {
if (pe > stringEnd - 5) {
raise_parse_error("incomplete unicode character escape sequence at '%s'", p);
} else {
uint32_t ch = unescape_unicode((unsigned char *) ++pe);
Expand Down
8 changes: 8 additions & 0 deletions test/json/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ def test_parse_broken_string
end
end

def test_invalid_unicode_escape
assert_raise(JSON::ParserError) { parse('"\u"') }
assert_raise(JSON::ParserError) { parse('"\ua"') }
assert_raise(JSON::ParserError) { parse('"\uaa"') }
assert_raise(JSON::ParserError) { parse('"\uaaa"') }
assert_equal "\uaaaa", parse('"\uaaaa"')
end

def test_parse_big_integers
json1 = JSON(orig = (1 << 31) - 1)
assert_equal orig, parse(json1)
Expand Down

0 comments on commit 86c0d4e

Please sign in to comment.