Skip to content
Tcl Source Code History Of Ticket 3604074fffffffffffffffffffffffffffffffff
Login

History Of Ticket 3604074fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 3604074fffffffffffffffffffffffffffffffff

  1. Ticket change [1d1bfdbf18] (rid 90736) by bjorngrathwohl on 2013-02-11 11:04:01:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      When I perform a match with five or more nested kleene stars, like the regular expression (((((a)*)*)*)*)* on the input string "a", Tcl goes into an infinite loop.  When there are four or fewer kleene-stars, it does not happen.
      If I change the expressions to use non-grouping parentheses, like (?:(?:(?:(?:(?:a)*)*)*)*)*, the problem disappears.
      
      % set exp "(((((a)*)*)*)*)*"
      (((((a)*)*)*)*)*
      % [regex $exp "a"]
      <LOOP>
      
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "bjorngrathwohl"
    10. subsystem initialized to: "None"
    11. title initialized to: "Inifinite loop when matching regular expression"
    12. type initialized to: "Bug"
  2. Ticket change [6256bb4b1c] (rid 92398) by sebres on 2013-02-11 19:02:06:

    1. icomment:
      More than strange use of repeatable group match. Of course, the infinite loop is not really expected behavior here, but why '*' again after '*' of self?
      
      Just for your info:
      % regexp -inline {((((a)*)))} a
      a a a a a
      % regexp -inline {((((a)*)*)*)*} a
      a {} {} {} {}
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  3. Ticket change [92d5e63812] (rid 105711) by bjorngrathwohl on 2013-02-11 19:55:48:

    1. icomment:
      Yes, I know that it is not a very realistic use of grouping parentheses, but I still think that it is a problem that you can cause an infinite loop in your program with this, rather innocent-looking, expression... Especially when it doesn't loop when given the expression ((((a)*)*)*)*.
      
      
    2. login: "bjorngrathwohl"
    3. mimetype: "text/plain"
    4. username: "bjorngrathwohl"
  4. Ticket change [b734cbf98e] (rid 125545) by dgp on 2013-02-11 20:27:15:

    1. icomment:
      What release of Tcl?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  5. Ticket change [c5941d7a29] (rid 112022) by dkf on 2013-02-11 20:29:24:

    1. subsystem changed to: "43. Regexp"
  6. Ticket change [8730c7c74a] (rid 131653) by bjorngrathwohl on 2013-02-11 20:34:54:

    1. icomment:
      I tried on version 8.6, downloaded as binary from http://www.activestate.com/activetcl/downloads, and version 8.5, which came bundled with OS X (I think, don't remember installling it...) I normally don't use Tcl myself.
      
      
    2. login: "bjorngrathwohl"
    3. mimetype: "text/plain"
    4. username: "bjorngrathwohl"
  7. Ticket change [41cfae7864] (rid 116253) by dkf on 2013-02-11 20:47:43:

    1. icomment:
      I've confirmed it in 8.4.7, 8.5.2 and 8.6 (trunk).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  8. Ticket change [7ee546c761] (rid 97485) by dkf on 2013-02-11 20:54:24:

    1. icomment:
      Problem *might* be in fixempties() in regc_nfa.c, or maybe in unempty() (called from fixempties). Partial stack calling probe (with trunk, numbers are count of samples):
      
                              2649 Tcl_RegexpObjCmd
                                2649 Tcl_GetRegExpFromObj
                                  2649 CompileRegexp
                                    2649 TclReComp
                                      2649 nfatree
                                        2649 nfatree
                                          2649 nfatree
                                            2649 nfatree
                                              2649 nfatree
                                                2649 nfanode
                                                  2649 optimize
                                                    2649 fixempties
                                                      2444 unempty
                                                        2367 copyouts
                                                          2165 cparc
                                                            2078 newarc
                                                              2061 newarc
                                                              17 allocarc
                                                                17 allocarc
                                                            87 cparc
                                                          202 copyouts
                                                        60 freearc
                                                          60 freearc
                                                        17 unempty
                                                      205 fixempties
      
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  9. Ticket change [3fde66a9a7] (rid 121534) by dgp on 2013-02-11 21:51:45:

    1. icomment:
      Loop is in fixempties().
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. subsystem changed to: "None"
    5. username: "dgp"
  10. Ticket change [38312e496e] (rid 112159) by dkf on 2013-02-11 22:03:12:

    1. foundin changed to: "obsolete: 8.4.7"
    2. priority changed to: "7 High"
    3. subsystem changed to: "43. Regexp"
  11. Ticket change [e1cd6e0766] (rid 87516) by dkf on 2013-02-11 22:08:51:

    1. icomment:
      That's where the loop is, but I don't know if it is where the problem is. :-)
      
      In particular, fixempties() and unempty() are rather familiar with each other, so I can't tell where the bug is between those two. (It might be that a normally-not-taken arm of unempty() is returning the wrong value.)
      
      I have *no* idea why the problem only happens when we get to depth 5. For all I know, it could be some compensatory code elsewhere that no longer applies.
      
        $ make shell
      [...]
        % regexp -about ((((a)*)*)*)*
        4 REG_UEMPTYMATCH
        % regexp -about (((((a)*)*)*)*)*
        ^Cmake: *** [shell] Interrupt
      
      Did I mention before that we really need either a proper RE maintainer, or to switch to a different RE engine?
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  12. Ticket change [604d5fefe3] (rid 115968) by sebres on 2013-02-11 22:40:33:

    1. icomment:
      Maybe just throw an error here, like python?
      # re.match('((a)*)', 'a').groups()
      ('a', 'a')
      # re.match('((a)*)*', 'a').groups()
      raise error, v # invalid expression
      error: nothing to repeat
      
      >[dkf] switch to a different RE engine
      I see a big compatibility problem here - many RE engines are incompatible to TCL RE.
      For example (python, java etc.) follow by "OR"-expression a "boolean" rules "first wins" instead of "hungry - large wins":
      [python]
      # re.match('(ab|abc)(cd|d)', 'abcd').groups()
      ('ab', 'cd')
      [tcl]
      % regexp -inline {(ab|abc)(cd|d)} abcd
      abcd abc d
      
      or see 3574242 for example (I do not know whether this is a bug):
      
      [tcl]
      % regexp -inline {((?:ab|abc){1}?)(cd|d){1}?} abcd
      abcd abc d
      % regexp -inline {((?:ab|abc){1,1}?)(cd|d){1,1}?} abcd
      abcd ab cd
      [python]
      # re.match('((?:ab|abc){1}?)(cd|d){1}?', 'abcd').groups()
      ('ab', 'cd')
      # re.match('((?:ab|abc){1,1}?)(cd|d){1,1}?', 'abcd').groups()
      ('ab', 'cd')
      
      Maybe is it possible to outsource RE engine in to a separate module, like python RE (to let user a choice) - something like this:
      reguse standard|extended|...
      
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  13. Ticket change [059ef494fd] (rid 89097) by dkf on 2013-02-11 22:53:00:

    1. icomment:
      I'd be OK with throwing an error (in the case of something like "<empty>*" as that's always troublesome) if we could detect it. Well, maybe the engine could do slightly better. I really don't know.
      
      This ought to be an error case or a success case, but definitely not a busyloop case.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  14. Ticket change [ac83b053d2] (rid 101308) by sebres on 2013-02-11 23:06:39:

    1. icomment:
      python is not consistent here also (does not always throw an error in this case) - however it has not a busy loop after 5-th group:
      # re.match('((a)*(b)*)*', 'abab').groups()
      ('', 'a', 'b')
      # re.match('(((a)*(b)*)*)*', 'abab').groups()
      ('', '', 'a', 'b')
      # re.match('(((((((a)*(b)*)*)*)*)*)*)*', 'ab').groups()
      ('', '', '', '', '', '', 'a', 'b')
      
      I try to fix this problem for tcl8.5 tomorrow...
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  15. Ticket change [fb7b804171] (rid 92071) by sebres on 2013-02-11 23:07:16:

    1. assignee changed to: "sebres"
  16. Ticket change [3a10399d9d] (rid 112498) by dgp on 2013-02-12 00:39:14:

    1. icomment:
      OK, there are graphs for which the fixempties
      algorithm just doesn't work.  This is one of them.
      continuing to explore.  Will report facts when I'm
      confident in them.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  17. Ticket change [bd23da1fa6] (rid 101862) by dgp on 2013-02-12 00:39:15:

    1. assignee changed to: "nobody"
    2. foundin changed to: "None"
    3. priority changed to: "5 Medium"
    4. subsystem changed to: "None"
  18. Ticket change [e515e3abc1] (rid 88073) by dgp on 2013-02-12 01:06:46:

    1. icomment:
      The trouble is when unempty is called to
      remove an EMPTY arc, and then copyouts()
      copies the same EMPTY arc back into place.
      The simplest graph I can imagine that would have
      this problem is one with two states A B and arc lists:
      
      A:  ->A  ->B
      B:  ->A  ->B
      
      where all those arcs are empty.  Add as many
      other states and arcs as you like.  One pass
      through fixempties() will leave that set of EMPTY
      arcs unchanged, so we loop forever still trying
      to change them (reduce them to 0).
      
      Now it may be that such a graph ought not be
      possible in this context, and the real bug is
      somewhere else that permits it to show up.
      But it wouldn't hurt to not assume that here.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  19. Ticket change [a25cd09d87] (rid 109875) by dgp on 2013-02-12 01:13:39:

    1. icomment:
      The simplest idea I have for a fix is to
      modify copyouts() so that it doesn't copy
      EMPTY arcs.  I have very little confidence
      this is the right thing to do, but I'll see what
      the test suite has to say.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  20. Ticket change [4538810eda] (rid 99315) by dgp on 2013-02-12 01:22:38:

    1. icomment:
      OK, that failed.  A more limited idea
      is to only refuse to copy EMPTY arcs
      that would become vacuous arcs in
      their new state.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  21. Ticket change [61bdb99128] (rid 92295) by dgp on 2013-02-12 01:25:22:

    1. icomment:
      test suite likes that fine, and :
      
      % regexp -about (((((a)*)*)*)*)*
      5 REG_UEMPTYMATCH
      
      After I tidy up, I'll put the patch on a branch,
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  22. Ticket change [0ee121ffee] (rid 94697) by dgp on 2013-02-12 01:52:09:

    1. icomment:
      see bug-3604074 branch for patch.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  23. Ticket change [07a3bbf2f6] (rid 89437) by dgp on 2013-02-12 01:52:18:

    1. assignee changed to: "dkf"
    2. foundin changed to: "obsolete: 8.4.19"
    3. priority changed to: "9 Immediate"
    4. subsystem changed to: "43. Regexp"
  24. Ticket change [cec4d6a24f] (rid 96106) by dgp on 2013-02-12 03:32:02:

    1. icomment:
      FWIW, the pre-Spencer RE engine (pre Tcl 8.1) could not
      handle such expressions.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  25. Ticket change [2035c8481e] (rid 91277) by dkf on 2013-02-12 04:14:42:

    1. assignee changed to: "dgp"
    2. icomment:
      You're far more knowledgeable about such things than I am, but I think it looks like a reasonable change to make; I can just about follow the reasoning even if I can't determine if that is the perfect fix. The test certainly looks good; that we pass it is a good sign (though producing an error would be nearly as good in my eyes to be honest!)
      
      Feel free to commit.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. username: "dkf"
  26. Ticket change [1f244b3f21] (rid 91094) by dgp on 2013-02-12 04:26:46:

    1. assignee changed to: "dkf"
    2. icomment:
      % regexp -about [string repeat ( 7]a[string repeat )* 7]
      7 REG_UEMPTYMATCH
      % regexp -about [string repeat ( 8]a[string repeat )* 8]
      <looks like there's still a problem...>
      
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  27. Ticket change [ef3ae8e0f4] (rid 108957) by dkf on 2013-02-12 16:06:42:

    1. assignee changed to: "dgp"
    2. icomment:
      Sure, but I don't know how to fix it.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. username: "dkf"
  28. Ticket change [7ba4171bd4] (rid 96941) by dgp on 2013-02-12 20:33:35:

    1. assignee changed to: "dkf"
    2. icomment:
      
      It's the same fundamental problem.  fixempties() does not work.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  29. Ticket change [669a5d8a89] (rid 102742) by dkf on 2013-02-12 21:03:04:

    1. assignee changed to: "dgp"
    2. icomment:
      But I'm not going to suddenly become able to fix it. Let me be clear, I could not have come up with the patch already proposed (though I can see that it looks reasonable) as I lack the specific experience/expertise.
      
      
    3. login: "dkf"
    4. mimetype: "text/plain"
    5. username: "dkf"
  30. Ticket change [d0610baa29] (rid 113170) by dgp on 2013-02-12 21:05:27:

    1. icomment:
      I'm not asking you to do anything.  I did seek a review,
      and you've done that.  I'm just recording my progress
      in case it sparks anything in anyone watching.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  31. Ticket change [056cd61b66] (rid 89062) by dkf on 2013-02-12 21:07:12:

    1. icomment:
      In that case it's dratted SF's stupid form that keeps assigning things back to me. Sorry for overinterpreting that.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  32. Ticket change [3b62428520] (rid 112735) by dgp on 2013-02-12 21:08:46:

    1. icomment:
      Any idea whether the postgresql folks have found/fixed
      the same issue?
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  33. Ticket change [481aee36c5] (rid 99828) by dgp on 2013-02-12 21:29:05:

    1. icomment:
      looking at 9.2.3 sources, apparently not. :P
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  34. Ticket change [ad6959c55f] (rid 101466) by sebres on 2013-02-13 00:24:59:

    1. icomment:
      posgres tested:
      postgres=# select 1 where 'a' ~ '((((a)*)*)*)*';
       ?column?
      ----------
              1
      (1 row)
      postgres=# select 1 where 'a' ~ '(((((a)*)*)*)*)*';
      !busyloop!
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  35. Ticket change [2dea5c69ea] (rid 119135) by sebres on 2013-02-13 01:48:22:

    1. icomment:
      I heard just now, postgres 9.2.3-1.pgdg60+1 (debian squeeze, 32 bit), it could not be reproduced.
      Very strange... in change log can't find nothing about regexp.
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  36. Ticket change [6d28cd2eec] (rid 128640) by dgp on 2013-02-13 03:00:41:

    1. icomment:
      if you can locate the patch, that would be interesting to look at.
      
      Meanwhile, the failing scenario seems to be when the subgraph made
      of of just the EMPTY arcs contains a cycle.  When that is true, fixempties()
      can fail.  It doesn't have to, it can get lucky with ordering and succeed, but
      success is not guaranteed when EMPTY cycles can show up.  Forbidding
      creation of single state cycles is helpful, but not the complete answer.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  37. Ticket change [cf8befedcc] (rid 113001) by sebres on 2013-02-13 16:48:46:

    1. icomment:
      9.1 can be reproduced
      9.2.2 not
      
      Candidates are:
      1. 9-1-3
      Fix regular expression back-references with * attached (Tom Lane)
      Rather than enforcing an exact string match, the code would effectively accept any string that satisfies the pattern sub-expression referenced by the back-reference symbol.
      A similar problem still afflicts back-references that are embedded in a larger quantified expression, rather than being the immediate subject of the quantifier. This will be addressed in a future PostgreSQL release.
      
      2. 9-1-5
      Fix extraction of common prefixes from regular expressions (Tom Lane)
      The code could get confused by quantified parenthesized subexpressions, such as ^(foo)?bar. This would lead to incorrect index optimization of searches for such patterns.
      
      3. 9-2
      Sync regular expression code with TCL 8.5.11 and improve internal processing (Tom Lane)
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  38. Ticket change [edb8981902] (rid 103943) by sebres on 2013-02-13 19:13:46:

    1. icomment:
      > dgp, please have a look here: 
      http://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=a9287de1760450e7fe3b4309ee1ba7ea2af39217
      
      
    2. login: "sebres"
    3. mimetype: "text/plain"
    4. username: "sebres"
  39. Ticket change [779ccd1bc1] (rid 89805) by dgp on 2013-02-14 01:44:50:

    1. icomment:
      
      The postgresql patch does not directly attack the flaws
      of fixempties().  I can only guess that the changes it
      makes somehow prevent the troublesome cases from
      reaching it.  At least the ones we know about and test.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  40. Ticket change [16e8525244] (rid 124793) by dgp on 2013-02-14 01:51:13:

    1. icomment:
      
      The 8-deep expression that still hangs in
      bug-3604074 branch reaches a point where 
      there are 8 states which have outgoing EMPTY
      arcs to states that also have outgoing EMPTY arcs.
      Looking at just those states and just EMPTY arcs,
      the graph is:
      
      A: G H E C F D
      B: E C F G H A
      C: E B D G H F
      D: C F H B G A
      E: C F D G A H
      F: B E G H A C
      G: A H D F C B
      H: A D F C E G
      
      After one pass through the fixempties() loop,
      the new graph is:
      
      A: F C E H G B
      B: H G F C E D
      C: H G D B E A
      D: G B H F C E
      E: A G D F C B
      F: A H G E B D
      G: C F D H A E
      H: E C F D A B
      
      Then the next pass through the loop
      will return the graph to the first state.
      To fundamentally solve this problem within
      fixempties() requires changing the algorithm
      to one which will not fall into this kind of a
      limit cycle.
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  41. Ticket change [74e3e5ae2c] (rid 105296) by dkf on 2013-02-14 02:41:16:

    1. icomment:
      The other approach might be to set a cap on the number of times round the loop (maybe 100? 1000? I don't know how much) and to error out when the limit is reached. Like that, we'd turn an infinite loop into a definite failure.
      
      Just throwing the idea out there in case that's felt to be a better approach.
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  42. Ticket change [135eca6031] (rid 124206) by dgp on 2013-02-14 03:49:22:

    1. icomment:
      Yes, if I don't find the right sort of graph reduction
      algorithm advice with reasonable effort, that's
      the way to go to at least make sure we avoid
      hanging Tcl.
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  43. Ticket change [9714ffd88c] (rid 106446) by dgp on 2013-02-14 04:20:12:

    1. icomment:
      
      Possibly relevant link:
      http://swtch.com/~rsc/regexp/regexp2.html
      
      Excerpt: "This particular backtracking implementation
      has one shortcoming that production implementations
      usually do not: regular expressions like (a*)* can
      cause infinite loops in the compiled program..."
      
      
      
      
    2. login: "dgp"
    3. mimetype: "text/plain"
    4. username: "dgp"
  44. Ticket change [f9c83cf372] (rid 91755) by dgp on 2013-02-15 04:06:05:

    1. assignee changed to: "dkf"
    2. icomment:
      
      New branch bug-3604074 offers a better fix.  Covers all
      (..(a)*...)* cases up until the number of states prompts
      refusal to compile the expression.
      
      
    3. login: "dgp"
    4. mimetype: "text/plain"
    5. username: "dgp"
  45. Ticket change [eb2c7e642a] (rid 103491) by dgp on 2013-02-15 22:33:29:

    1. assignee changed to: "dgp"
    2. closedate changed to: "2013-02-15T15:33:29"
    3. closer changed to: "dgp"
    4. icomment:
      
      
      allow_comments - 1
      
      Fix merged to all release branches
      
      
    5. login: "dgp"
    6. mimetype: "text/plain"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
    9. username: "dgp"