You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The regex() generator crashes with a ReverseRegex\Exception on patterns using * or +. #193
I was using the regex() generator and ran into a consistent crash. It happens whenever the regex pattern includes an unbounded quantifier like * or +. It took a bit of digging to figure out what was going on.
1. The problem is in a dependency.
The issue comes from the icomefromthenet/reverse-regex library. It has a SimpleRandom class that's used to generate numbers. This class has a hardcoded limit and throws an exception if it's asked to generate a number larger than about 2.7 million.
When reverse-regex sees a * in a pattern, it sets the "max repeats" to a huge number. This huge number gets passed to SimpleRandom, which then immediately crashes.
2. The fix seems simple: use another random number generator.
The interesting part is that reverse-regex already has another generator, MersenneRandom, that doesn't have this low limit.
The bug in Eris is that RegexGenerator.php is hardcoded to only use the broken one:
// in Eris\Generator\RegexGenerator.php$gen = newSimpleRandom($rand->rand());
Just changing this to use the other generator should fix the crash and make the regex() helper work with * and + patterns.
For a longer-term solution, reverse-regex also has a GeneratorFactory. If Eris used that, it wouldn't be tied to one specific implementation. You could even add an option to let us choose the generator, which would be pretty cool.
4. That dependency is also a bit old.
By the way, icomefromthenet/reverse-regex seems to be unmaintained and doesn't support modern PHP versions.
Some people have forked it to get it working on newer PHP releases. For example, these pull requests look promising:
A nice side-effect of these modernized forks is that they use PHP's native mt_rand() instead of the library's own implementation in PHP. This would probably give a decent speed-up.
The regex() generator is a really cool and useful feature. It would be awesome to keep it, but right now things are a bit brittle. Making it more solid would be a big help.
Activity
philippedev101 commentedon Sep 15, 2025
@ilario-pierbattista you should enable the issues tab at https://github.com/ilario-pierbattista/ReverseRegex when you want to encourage contributions. Anyway the reproduction can be found here https://github.com/philippedev101/reverseregex-unbounded-repro
philippedev101 commentedon Sep 15, 2025
What should happen in this ticket is that eris no longer uses the SimpleRandom generator.
Use MersenneRandom in regex() generator to support unbounded quantifi…
Bound * and + in regex() via reverse-regex Parser::setUnboundedMax() (g…
Make the reverse-regex random generator configurable in regex() (gior…
Select the reverse-regex random generator by name via GeneratorFactory (
Type the $random docblock as string to satisfy Psalm (giorgiosironi#193)
Require reverse-regex ^0.7.0 (giorgiosironi#193)
Fix regex() generator with unbounded quantifiers (giorgiosironi#193)
Fix regex() generator on unbounded quantifiers (* and +) and make it …
ilario-pierbattista commentedon Oct 10, 2026
hi @philippedev101 unfortunatly MersenneRandom by itself won't work. Max is too large and generation never ends.
In #217 I've added the possibility to configure
Also, I've released https://github.com/ilario-pierbattista/ReverseRegex/releases/tag/0.7.0 which sets a much lower default limit.
Thank you