Explorer: Fuzzer issue around infinite recursion (#2741)

I limited the stack size to 1K we can change it or make it dynamic from CLI later

Closes #2733
This commit is contained in:
Amr Hesham
2023-04-06 16:50:02 -07:00
committed by GitHub
parent 8cb3f00f1b
commit 87df7f7c43
3 changed files with 26 additions and 0 deletions
+2
View File
@@ -119,6 +119,8 @@ class ActionStack {
void Pop() { todo_.Pop(); }
auto Count() const -> int { return todo_.Count(); }
private:
// Pop any ScopeActions from the top of the stack, propagating results as
// needed, to restore the invariant that todo_.Top() is not a ScopeAction.
+4
View File
@@ -952,6 +952,10 @@ auto Interpreter::CallFunction(const CallExpression& call,
Nonnull<const Value*> fun,
Nonnull<const Value*> arg,
ImplWitnessMap&& witnesses) -> ErrorOr<Success> {
constexpr int StackSizeLimit = 1000;
if (todo_.Count() > StackSizeLimit) {
return ProgramError(call.source_loc()) << "stack overflow";
}
if (trace_stream_->is_enabled()) {
*trace_stream_ << "calling function: " << *fun << "\n";
}
@@ -0,0 +1,20 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// RUN: %{not} %{explorer-run}
// RUN: %{not} %{explorer-run-trace}
package EmptyIdentifier impl;
fn A() {
// CHECK:STDERR: RUNTIME ERROR: {{.*}}/explorer/testdata/function/fail_recursion_stackoverflow.carbon:[[@LINE+1]]: stack overflow
A();
}
fn Main() -> i32
{
A();
return 0;
}