From bcc711e731261a55f232f12a9554190189b5d856 Mon Sep 17 00:00:00 2001 From: Robert Fancsik Date: Wed, 15 Dec 2021 10:28:18 +0100 Subject: [PATCH] Add stack-overflow check for Array.prototype.{flat, flatMap} (#4899) This patch fixes #4890 JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu --- .github/workflows/gh-actions.yml | 4 ++-- .../ecma-builtin-array-prototype.c | 3 +++ .../es.next/regression-test-issue-4890.js | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/jerry/es.next/regression-test-issue-4890.js diff --git a/.github/workflows/gh-actions.yml b/.github/workflows/gh-actions.yml index 4a7d5bf8e..76cd3fcca 100644 --- a/.github/workflows/gh-actions.yml +++ b/.github/workflows/gh-actions.yml @@ -162,7 +162,7 @@ jobs: - run: >- $RUNNER -q --jerry-tests --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 - --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 + --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 ASAN_Tests_Debug: runs-on: ubuntu-latest @@ -175,7 +175,7 @@ jobs: - run: >- $RUNNER -q --jerry-tests --build-debug --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 - --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 + --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 UBSAN_Tests: runs-on: ubuntu-latest diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c index 0289e2466..7201a0c21 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-array-prototype.c @@ -28,6 +28,7 @@ #include "ecma-objects.h" #include "ecma-string-object.h" +#include "jcontext.h" #include "jrt.h" #include "lit-char-helpers.h" @@ -2659,6 +2660,8 @@ ecma_builtin_array_flatten_into_array (ecma_value_t target, /**< target will con ecma_value_t mapped_value, /**< mapped value */ ecma_value_t thisArg) /**< this arg */ { + ECMA_CHECK_STACK_USAGE (); + /* 7. */ ecma_length_t target_index = start; diff --git a/tests/jerry/es.next/regression-test-issue-4890.js b/tests/jerry/es.next/regression-test-issue-4890.js new file mode 100644 index 000000000..ccea497a1 --- /dev/null +++ b/tests/jerry/es.next/regression-test-issue-4890.js @@ -0,0 +1,23 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +let array = new Array(1); +array.splice(1, 0, array); + +try { + array.flat(Infinity); + assert(false); +} catch (e) { + assert(e instanceof RangeError) +}