That's an interesting thought. Do you happen to know any example of a pattern that can be used that way? I could find/think of none.Xgoff wrote:the pattern matcher a potential DoS target
table.pack and LOVE
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: table.pack and LOVE
When I write def I mean function.
Re: table.pack and LOVE
you can quite easily invoke catastrophic backtrackingkikito wrote:That's an interesting thought. Do you happen to know any example of a pattern that can be used that way? I could find/think of none.Xgoff wrote:the pattern matcher a potential DoS target
for example the code: ("a"):rep(100):match(patt)
where patt might be:
* a+a+b: too low to measure
* a+a+a+b: 0.08 seconds
* a+a+a+a+b: 1.3 seconds
* a+a+a+a+a+b: 20.3 seconds
etc...
and this is only matching 100 characters!
it might be possible to wrap those functions to use a pattern simplifier (eg to reduce something like `x+x+x+` to just `xxx+`) and run it over pattern strings in order to avoid this, but i don't know if this is feasible in general, or if optimizations like that are always valid (such as if they involve captures)
for fun, the "equivalent" patterns to those above (aa+b, aaa+b, aaaa+b, aaaaa+b) all complete instantly
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: table.pack and LOVE
Well, a simple alternative would be to not expose string.match in the first place (set it to nil before executing the protected code, and restore it on exit). I'm already doing that for string.rep. Thanks for the feedback!
When I write def I mean function.
Re: table.pack and LOVE
sure, but then you'll have to deal with people who need patterns for somethingkikito wrote:Well, a simple alternative would be to not expose string.match in the first place (set it to nil before executing the protected code, and restore it on exit). I'm already doing that for string.rep. Thanks for the feedback!
i guess an alternative could be to reimplement the pattern functions in pure lua so that they could be monitored by hooks, but...
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot], TheJayDizzle and 10 guests