in reply to Re: Complex regular subexpression recursion limit
in thread Complex regular subexpression recursion limit

What's the bug? The presence of a recursion limit doesn't seem by itself to be a bug—we've long (always?) had it for subroutines (Deep recursion on subroutine "%s"), and quantifiers {n,m} have also been limited (Quantifiers). It seems that both of these are intentional, trading some power for efficiency and safety. Is there something else that I'm missing?

UPDATE: Obviously I didn't read my own link very well. I forgot that the Deep recursion message was a warning, not a fatal error.

Replies are listed 'Best First'.
Re^3: Complex regular subexpression recursion limit
by ikegami (Patriarch) on Dec 03, 2009 at 17:52 UTC

    First of all, there is no limit on recursion depth. There's a suppressible warning when you attain a certain depth, that's all.

    Secondly, there is no efficiently gained by limiting the number of iterations. We're talking about using a 32-bit variable instead of a 16-bit variable on a 32-bit system.

    And it's not just a theoretical bug. There exists desire for the ability to match longer strings.

Re^3: Complex regular subexpression recursion limit
by JavaFan (Canon) on Dec 03, 2009 at 17:51 UTC
    It's a bug because the regexp engine isn't recursive anymore. Limiting quantifier size for "efficiency and safety" reasons makes as much sense stopping the following loop:
    for (1 .. 34000) { print $_ }
    after it printed 32766.

    Note that the "deep recursion" you are referring to is a warning, perl won't stop the recursion. But the Complex regular subexpression recursion limit makes perl just say "oh well, I had enough - I'll just pretend it doesn't match". That's wrong. It may even be exploitable.

      Limiting quantifier size for "efficiency and safety" reasons makes as much sense stopping the following loop
      I wasn't proposing a limit on quantifier size, just observing that it's already present (and speculating on why).
      Note that the "deep recursion" you are referring to is a warning, perl won't stop the recursion. But the Complex regular subexpression recursion limit makes perl just say "oh well, I had enough - I'll just pretend it doesn't match". That's wrong. It may even be exploitable.
      Obviously I didn't read the perldiag page very well, despite linking to it. :-) Now I understand the difference—thanks. (Mainly I missed the fact that the regular expression match fails with a warning, rather than dieing, because I didn't actually run the code myself.)

        Mainly I missed the fact that the regular expression match fails with a warning, rather than dieing

        I missed that too, so it wasn't part of my reasoning