From 27cd7cf8f816f1d1dd465c28a43fc0fcd25c48d6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 5 May 2024 12:27:17 +0900 Subject: feat: limit call stack size --- src/Execution/Stack.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Execution/Stack.php') diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php index 424f8c6..6d2a2aa 100644 --- a/src/Execution/Stack.php +++ b/src/Execution/Stack.php @@ -30,6 +30,9 @@ final class Stack public function pushFrame(Frame $frame): void { + if ($this->getCallStackLimit() <= count($this->frames)) { + throw new StackOverflowException(); + } $this->push($frame); $this->frames[] = $frame; $this->currentFrame = $frame; @@ -179,6 +182,11 @@ final class Stack return $this->currentFrame; } + public function getCallStackLimit(): int + { + return 1024; + } + private function push(int|float|Ref|Frame|Label $entry): void { $this->entries[] = $entry; -- cgit v1.2.3-70-g09d2