Skip to content

Commit bcc711e

Browse files
author
Robert Fancsik
authored
Add stack-overflow check for Array.prototype.{flat, flatMap} (#4899)
This patch fixes #4890 JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 42523bd commit bcc711e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-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-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-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-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-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-array-prototype.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ecma-objects.h"
2929
#include "ecma-string-object.h"
3030

31+
#include "jcontext.h"
3132
#include "jrt.h"
3233
#include "lit-char-helpers.h"
3334

@@ -2659,6 +2660,8 @@ ecma_builtin_array_flatten_into_array (ecma_value_t target, /**< target will con
26592660
ecma_value_t mapped_value, /**< mapped value */
26602661
ecma_value_t thisArg) /**< this arg */
26612662
{
2663+
ECMA_CHECK_STACK_USAGE ();
2664+
26622665
/* 7. */
26632666
ecma_length_t target_index = start;
26642667

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
let array = new Array(1);
16+
array.splice(1, 0, array);
17+
18+
try {
19+
array.flat(Infinity);
20+
assert(false);
21+
} catch (e) {
22+
assert(e instanceof RangeError)
23+
}

0 commit comments

Comments
 (0)