News for hackers. Stuff that matters.
Re:Ruby 3.2 preview 1 with support for WASM compilation by speedgoose on Thursday April 07, 2022 @02:20PM (#30948374)
A timeout for regexps makes so much sense. And it would end all these denial of service security reports.
Re:Ruby 3.2 preview 1 with support for WASM compilation by Thaxll on Thursday April 07, 2022 @03:35PM (#30949353)
It does not make sense to me, best solution is to have an implementation like re2 that does not have those problems.

Adding a timeout is a bit strange, first because you don't know in advance how long it's going to take for large search. The timeout is a failsafe against something that should be fixed in the first place.

Re:Ruby 3.2 preview 1 with support for WASM compilation by JohnBooty on Thursday April 07, 2022 @06:23PM (#30951051)
You can use re2 in Ruby if you like - it's just not the default. https://github.com/mudge/re2

    best solution is to have an implementation like re2 that does not have those problems.
By design RE2 isn't fully compatible with Onigmo. As another poster mentioned, a hybrid "use RE2 when possible; fall back to Onigmo otherwise" approach was considered and rejected for well-explained reasons https://bugs.ruby-lang.org/issues/18653

Maybe in addition to `Regexp.timeout = 1.0` there could also be a `Regexp.parser = :re2` option with `:onigmo` being the default.

Re:Ruby 3.2 preview 1 with support for WASM compilation by messe on Thursday April 07, 2022 @04:14PM (#30949806)
I think a limit on stack/recursion/backtracking depth would be tad a bit more elegant than a timeout and would keep your code behaviour the same between different machines.
Re:Ruby 3.2 preview 1 with support for WASM compilation by capableweb on Thursday April 07, 2022 @04:37PM (#30950036)
It'd be harder to control perceived performance of user facing applications though. If I can set the timeout, I can guarantee that something happens within X seconds, instead of within X iterations which could have different performance machine to machine.
Re:Ruby 3.2 preview 1 with support for WASM compilation by MaxLeiter on Thursday April 07, 2022 @04:40PM (#30950068)
is this not the halting problem? You can guarantee a certain depth isnt reached but you cant guarantee a recursion will unwind or anything like that
Re:Ruby 3.2 preview 1 with support for WASM compilation by johncolanduoni on Friday April 08, 2022 @12:31AM (#30953342)
No, because we’re not trying to find out if the computation will ever halt with unbounded time. It just determines if it will halt after a certain number of steps, which you can always determine by executing that number of steps and bailing out.
Re:Ruby 3.2 preview 1 with support for WASM compilation by __s on Thursday April 07, 2022 @05:52PM (#30950778)
It's not the halting problem; it's bounding computational depth

Their suggestion is essentially making stack overflow a feature in regex, & then allowing that stack depth to be tuned

Re:Ruby 3.2 preview 1 with support for WASM compilation by smohare on Thursday April 07, 2022 @10:32PM (#30952717)
Wooosh
Re:Ruby 3.2 preview 1 with support for WASM compilation by jatone on Thursday April 07, 2022 @03:44PM (#30949475)
thats the problem with all these syntax sugar features in languages. you literally can't change them without blowing up your entire ecosystem.
Re:Ruby 3.2 preview 1 with support for WASM compilation by djur on Thursday April 07, 2022 @06:38PM (#30951155)
How would this problem be different if Ruby did not have syntax support for regexes and instead offered a regex module in the standard library?
Re:Ruby 3.2 preview 1 with support for WASM compilation by FrancoisBosun on Thursday April 07, 2022 @11:05PM (#30952917)
If it isn’t syntax then it is a function/method call. By being a method call, one can define default options, allowing overridability.
Re:Ruby 3.2 preview 1 with support for WASM compilation by djur on Friday April 08, 2022 @12:16AM (#30953285)
They could easily add another regex flag to indicate a "safe" regex. That really isn't the problem here. The problem is that adding a safe regex engine doesn't retroactively fix the thousands and thousands of regexes in gems which can't be unilaterally forced over to the new engine.
Re:Ruby 3.2 preview 1 with support for WASM compilation by jatone on Monday April 11, 2022 @11:26AM (#30990115)
actually that is the problem. no they can't 'easily' add a new flag (or they would have). it doesn't fix the problem of being broken by default and any fundamental change in behavior will lead to problems as well.

the point is the language is broken fundamentally and because its syntax sugar there isn't anything you can do realistically. a function call can be replaced, deprecated, and then removed and all of that can be automated and be non-disruptive over a few releases.

Re:Ruby 3.2 preview 1 with support for WASM compilation by sitkack on Thursday April 07, 2022 @11:21PM (#30953006)
> It does not make sense to me

What are your credentials for being you?

Re:Ruby 3.2 preview 1 with support for WASM compilation by sitkack on Monday April 11, 2022 @01:54PM (#30992383)
The grand-parent post exhibits feigned confusion and using opinions as arguments. It also proposes an _optimal_ solution that will most likely not get implemented in place of pragmatic solution. We see this kind of argumentation when discussing crypto libraries.

The OP is not _confused_, they just don't like the solution.

Re:Ruby 3.2 preview 1 with support for WASM compilation by kookamamie on Friday April 08, 2022 @01:08AM (#30953519)
It makes zero sense, if I'm completely honest. Why stop to regexps? What about every other long-running function? This is better handled on a layer above, in a general fashion - imagine a server running some queries and being able to kill/discard/interrupt them in case they seem stuck.
Re:Ruby 3.2 preview 1 with support for WASM compilation by speedgoose on Friday April 08, 2022 @01:11AM (#30953536)
If you don’t stop long processes on a server, you expose yourself to denial of service attacks. It’s good practice to have a maximum duration for database queries as well.
Re:Ruby 3.2 preview 1 with support for WASM compilation by kookamamie on Friday April 08, 2022 @05:28AM (#30954995)
Of course you should limit the query duration - just not on some arbitrary function-level like done here. To me this sounds like PHP-level incompetence on API design.