Skip to content

Commit dfc001d

Browse files
author
Robert Fancsik
authored
Prevent stack-overflow in json internalize property (#4877)
This patch fixes #4848. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 070096f commit dfc001d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

.github/workflows/gh-actions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
- run: >-
163163
$RUNNER -q --jerry-tests
164164
--buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold
165-
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
165+
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
166166
167167
ASAN_Tests_Debug:
168168
runs-on: ubuntu-latest
@@ -175,7 +175,7 @@ jobs:
175175
- run: >-
176176
$RUNNER -q --jerry-tests --build-debug
177177
--buildoptions=--stack-limit=0,--compile-flag=-fsanitize=address,--compile-flag=-m32,--compile-flag=-fno-omit-frame-pointer,--compile-flag=-fno-common,--compile-flag=-O2,--debug,--system-allocator=on,--linker-flag=-fuse-ld=gold
178-
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
178+
--skip-list=parser-oom.js,parser-oom2.js,stack-limit.js,regression-test-issue-4848.js,regression-test-issue-4890.js,regression-test-issue-2190.js,regression-test-issue-2258-2963.js,regression-test-issue-2448.js,regression-test-issue-2905.js,regression-test-issue-3785.js,proxy-evil-recursion.js
179179
180180
UBSAN_Tests:
181181
runs-on: ubuntu-latest

jerry-core/ecma/builtin-objects/ecma-builtin-json.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "ecma-objects-general.h"
2727
#include "ecma-objects.h"
2828

29+
#include "jcontext.h"
2930
#include "jrt-libc-includes.h"
3031
#include "jrt.h"
3132
#include "lit-char-helpers.h"
@@ -635,6 +636,8 @@ ecma_builtin_json_internalize_property (ecma_object_t *reviver_p, /**< reviver f
635636
JERRY_ASSERT (holder_p);
636637
JERRY_ASSERT (name_p);
637638

639+
ECMA_CHECK_STACK_USAGE ();
640+
638641
/* 1. */
639642
ecma_value_t value = ecma_op_object_get (holder_p, name_p);
640643

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var once = false;
16+
var m = 1;
17+
18+
function JSEtest(){
19+
if(!once){
20+
m = new Array(1, 2, 3);
21+
this[2] = m;
22+
}
23+
once = true;
24+
return this[2] = m;
25+
}
26+
27+
try {
28+
JSON.parse("[1, 2, [4, 5]]", JSEtest);
29+
assert(false);
30+
} catch (e){
31+
assert(e instanceof RangeError);
32+
}

0 commit comments

Comments
 (0)