Closed refi64 closed 8 years ago
I think this is a stack overflow. I'm guessing that, since *
is greedy, it keeps spawning threads? Or something?
Also, this fails with an empty input.
The problem:
Take (?:a?)*
. The a?
spawns a thread that will cut to the *
. When it fails to match, it then executes that thread, which goes to the *
. Because the match was technically successful, the *
will jump back to the a?
...and the process loops forever. But the initial thread that *
pushes at the beginning stays on the stack, eventually causing an overflow.
In Python and Perl, the group seems to never, ever have any contents. I find that slightly odd, since I would think that, since ?
is greedy, it would instantly eat up the first character...?
In Russ Cox's VM, he doesn't fork again at the end of *
, instead just doing a jump back to the top. That may fix the issue.
(?:a*)*
segfaults. Seems like such an innocent regex...Worth noting that all of the following work:
(?:a*)
(?:a*)?
(?:a+)+
(?:a?)?
But the following also do not work:
(?:a?)*
(?:a*)+
Seems to be a threading issue. Before the introduction of threads, they looped indefinitely.