Skip to content

Commit e4113ad

Browse files
authored
Make the preprocessor checks a little stricter + limit the maximum time for preprocessing (#3616)
1 parent 86e495e commit e4113ad

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lua/entities/gmod_wire_expression2/base/preprocessor.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,21 @@ function PreProcessor:Process(buffer, directives, ent)
403403
self.ignorestuff = true
404404
end
405405

406+
-- to avoid hangs
407+
local start_time = SysTime()
408+
406409
for i, line in ipairs(lines) do
407410
self.readline = i
408411

409-
-- 2 regex changed from 500 to 15000
410-
local ok = pcall(function() WireLib.CheckRegex(line, "^(.-)%s*$", {[0] = 50000000, 15000, 15000, 150, 70, 40}) end)
412+
-- 2 regex changed from 500 to 10000, to avoid hangs
413+
local ok = pcall(function() WireLib.CheckRegex(line, "^(.-)%s*$", {[0] = 50000000, 15000, 10000, 150, 70, 40}) end)
411414
if not ok then self:Error("Line strip regex is too complex!") goto cont end
412415

416+
if SysTime() > start_time + 0.1 then
417+
self:Error("Preprocessing take too long!")
418+
break
419+
end
420+
413421
line = string.TrimRight(line)
414422
line = self:RemoveComments(line)
415423
line = self:ParseDirectives(line)

0 commit comments

Comments
 (0)