Change: Limit total script ops that can be consumed by a list valuate (#11670)

This commit is contained in:
Jonathan G Rennison
2024-01-02 18:02:12 +00:00
committed by GitHub
parent 502a52edd5
commit 48b6b1844a
5 changed files with 36 additions and 0 deletions

View File

@@ -116,6 +116,8 @@ SQVM::SQVM(SQSharedState *ss)
_can_suspend = false;
_in_stackoverflow = false;
_ops_till_suspend = 0;
_ops_till_suspend_error_threshold = INT64_MIN;
_ops_till_suspend_error_label = nullptr;
_callsstack = nullptr;
_callsstacksize = 0;
_alloccallsstacksize = 0;
@@ -744,6 +746,10 @@ exception_restore:
{
DecreaseOps(1);
if (ShouldSuspend()) { _suspended = SQTrue; _suspended_traps = traps; return true; }
if (IsOpsTillSuspendError()) {
Raise_Error(fmt::format("excessive CPU usage in {}", _ops_till_suspend_error_label));
SQ_THROW();
}
const SQInstruction &_i_ = *ci->_ip++;
#ifdef _DEBUG_DUMP

View File

@@ -168,6 +168,8 @@ public:
SQBool _can_suspend;
SQInteger _ops_till_suspend;
SQInteger _ops_till_suspend_error_threshold;
const char *_ops_till_suspend_error_label;
SQBool _in_stackoverflow;
bool ShouldSuspend()
@@ -175,6 +177,11 @@ public:
return _can_suspend && _ops_till_suspend <= 0;
}
bool IsOpsTillSuspendError()
{
return _ops_till_suspend < _ops_till_suspend_error_threshold;
}
void DecreaseOps(SQInteger amount)
{
if (_ops_till_suspend - amount < _ops_till_suspend) _ops_till_suspend -= amount;