Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing incomplete unicode escape "\uaaa" #733

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
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
Loading