Repository navigation
fix(vm): charge goto loops and native re-entry to the instruction and depth limits - #446
Open
adriencohen wants to merge 1 commit into
Open
adriencohen wants to merge 1 commit into
adriencohen wants to merge 1 commit into
Conversation
… depth limits goto loops, __call chains, metamethod work and recursion that re-enters Lua from native code (pcall, stdlib callbacks, Lua.call_function/3 from a host callback) were not charged to :max_instructions or :max_call_depth, so a script could loop or recurse without bound.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A script could loop or recurse without bound despite
:max_instructionsand:max_call_depth:gotoloops,__callchains, metamethod work, and recursion that re-enters the VM from native code (pcall, stdlib callbacks, a host callback callingLua.call_function!/3) were never charged. Fixes #411.::top:: goto toplocal function f() return pcall(f) end return f()local a = {} setmetatable(a, {__call = a}) return a()'__call' chain too longin <1 mstable.sortcomparator that callstable.sortstack overflowin 3 msmax_instructions: 1_000_000, max_call_depth: 200, each script in a process capped at 512 MB, Apple M2, OTP 29.A backward
gotonow ticks the budget like a loop back-edge, and every call into a function from native code costs one tick and one depth level, native callees included. A top-levelLua.call_function/3now costs one depth level and one instruction, like a call made from Lua. A direct call from Lua to a native function, and the native's own work, are still uncharged.