Reapply "[vm] Tighten stack overflow check in the parser."

Use a smaller recursion limit that handles IA32 ASAN.

Bug: https://github.com/dart-lang/sdk/issues/31158
Change-Id: If2a5694722619d100be2e91f952210d92af4ec7c
Reviewed-on: https://dart-review.googlesource.com/24623
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2017-11-30 02:11:22 +00:00 committed by commit-bot@chromium.org
parent e98519a5c9
commit 9b7b91ee66
3 changed files with 6 additions and 19 deletions

View file

@ -141,12 +141,12 @@ class RecursionChecker : public ValueObject {
public:
explicit RecursionChecker(Parser* p) : parser_(p) {
parser_->recursion_counter_++;
// No need to check the stack unless the parser is in an unusually deep
// recurive state. Thus, we omit the more expensive stack checks in
// the common case.
const int kMaxUncheckedDepth = 100; // Somewhat arbitrary.
if (parser_->recursion_counter_ > kMaxUncheckedDepth) {
parser_->CheckStack();
// This limit also protects against stack overflow in the flow graph builder
// and some optimization passes, which may use more stack than the parser
// for the same function.
// The limit is somewhat arbitrary.
if (parser_->recursion_counter_ > 256) {
parser_->ReportError("stack overflow while parsing");
}
}
~RecursionChecker() { parser_->recursion_counter_--; }
@ -6547,14 +6547,6 @@ void Parser::ParseTopLevel() {
pending_classes.Add(toplevel_class, Heap::kOld);
}
void Parser::CheckStack() {
uword c_stack_pos = Thread::GetCurrentStackPointer();
uword c_stack_limit = OSThread::Current()->stack_limit_with_headroom();
if (c_stack_pos < c_stack_limit) {
ReportError("stack overflow while parsing");
}
}
void Parser::ChainNewBlock(LocalScope* outer_scope) {
Block* block = new (Z) Block(current_block_, outer_scope,
new (Z) SequenceNode(TokenPos(), outer_scope));

View file

@ -454,9 +454,6 @@ class Parser : public ValueObject {
const Function& constructor,
const TypeArguments& type_arguments);
// Report error if parsed code is too deeply nested; avoid stack overflow.
void CheckStack();
// Report already formatted error.
static void ReportError(const Error& error);

View file

@ -10,8 +10,6 @@
[ $compiler == precompiler && $runtime == dart_precompiled ]
stacktrace_demangle_ctors_test: RuntimeError
deep_nesting1_negative_test: Skip # Issue 31158
deep_nesting2_negative_test: Skip # Issue 31158
[ $compiler == precompiler && $runtime == dart_precompiled && $checked ]
assertion_initializer_const_error2_test/cc02: Crash