Skip to content

Commit 823760c

Browse files
committed
Merge branch 'abrom-fix-parse-segfault'
2 parents 7555eda + b59368a commit 823760c

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

ext/json/ext/parser/parser.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,9 +2363,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
23632363
char buf[4];
23642364

23652365
if (bufferSize > MAX_STACK_BUFFER_SIZE) {
2366+
# ifdef HAVE_RB_ENC_INTERNED_STR
2367+
bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1);
2368+
# else
23662369
bufferStart = buffer = ALLOC_N(char, bufferSize);
2370+
# endif
23672371
} else {
2372+
# ifdef HAVE_RB_ENC_INTERNED_STR
2373+
bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1);
2374+
# else
23682375
bufferStart = buffer = ALLOCA_N(char, bufferSize);
2376+
# endif
23692377
}
23702378

23712379
while (pe < stringEnd) {

ext/json/ext/parser/parser.rl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,17 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
462462
char buf[4];
463463

464464
if (bufferSize > MAX_STACK_BUFFER_SIZE) {
465+
# ifdef HAVE_RB_ENC_INTERNED_STR
466+
bufferStart = buffer = ALLOC_N(char, bufferSize ? bufferSize : 1);
467+
# else
465468
bufferStart = buffer = ALLOC_N(char, bufferSize);
469+
# endif
466470
} else {
471+
# ifdef HAVE_RB_ENC_INTERNED_STR
472+
bufferStart = buffer = ALLOCA_N(char, bufferSize ? bufferSize : 1);
473+
# else
467474
bufferStart = buffer = ALLOCA_N(char, bufferSize);
475+
# endif
468476
}
469477

470478
while (pe < stringEnd) {

tests/json_parser_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def test_parse_simple_objects
8484
assert_equal({ "a" => 23 }, parse(' { "a" : 23 } '))
8585
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
8686
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
87+
assert_equal({ "" => 123 }, parse('{"":123}'))
8788
end
8889

8990
def test_parse_numbers

0 commit comments

Comments
 (0)