Skip to content

Commit

Permalink
Merge branch 'abrom-fix-parse-segfault'
Browse files Browse the repository at this point in the history
  • Loading branch information
flori committed May 16, 2022
2 parents 7555eda + b59368a commit 823760c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2363,9 +2363,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
char buf[4];

if (bufferSize > MAX_STACK_BUFFER_SIZE) {
# ifdef HAVE_RB_ENC_INTERNED_STR
bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1);
# else
bufferStart = buffer = ALLOC_N(char, bufferSize);
# endif
} else {
# ifdef HAVE_RB_ENC_INTERNED_STR
bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1);
# else
bufferStart = buffer = ALLOCA_N(char, bufferSize);
# endif
}

while (pe < stringEnd) {
Expand Down
8 changes: 8 additions & 0 deletions ext/json/ext/parser/parser.rl
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
char buf[4];

if (bufferSize > MAX_STACK_BUFFER_SIZE) {
# ifdef HAVE_RB_ENC_INTERNED_STR
bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1);
# else
bufferStart = buffer = ALLOC_N(char, bufferSize);
# endif
} else {
# ifdef HAVE_RB_ENC_INTERNED_STR
bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1);
# else
bufferStart = buffer = ALLOCA_N(char, bufferSize);
# endif
}

while (pe < stringEnd) {
Expand Down
1 change: 1 addition & 0 deletions tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def test_parse_simple_objects
assert_equal({ "a" => 23 }, parse(' { "a" : 23 } '))
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
assert_equal({ "" => 123 }, parse('{"":123}'))
end

def test_parse_numbers
Expand Down

0 comments on commit 823760c

Please sign in to comment.