Subject: bug#22146: Stack overflow in reftex-parse-all

From: Tassilo Horn <[email-masked]>
Date: Sun, 13 Dec 2015 17:55:27 +0100

David Kastrup <[email-masked]> writes:

>>     (re-search-forward "\\[[^]]*\\<label")
>>
>> at the beginning of the buffer suggested by Nils.  So, it doesn't
>> seem there is an incomplete match, but simply "\\[[^]]*" is too
>> greedy.
>
> This expression contains only a single explicit wildcard.  A stack
> overflow for it most certainly is a bug.  Is this really fixed in 25.1
> or is there just a larger stack?

I also get a stack overflow with this starting with a buffer size of
about 800 lines.  But I can run

  (re-search-forward reftex-everything-regexp nil t)

without problems even after adding 100.000 more "foo foo foo..." lines
to the test file...

Ah, `reftex-everything-regexp' doesn't include that problematic regex
anymore.
Now it contains "\\[[^[]]*\\<label"
instead of      "\\[[^]]*\\<label".

Well, that new regexp has not this problem because it is wrong and
doesn't match keyval style labels anymore.  That problem has been
introduced by:

--8<---------------cut here---------------start------------->8---
commit 32a488344057f210b51f4618feb3a85799eef0c5
Author: Nils Ackermann <[email-masked]>
Date:   Tue Jun 16 09:24:47 2015 +0200

    Improve reftex-label-regexps default value
    
    * lisp/textmodes/reftex-vars.el (reftex-label-regexps): Make
    keyvals label regexp more strict to better cope with unbalanced
    brackets common in math documents.
--8<---------------cut here---------------end--------------->8---

I just now changed the regexp (`reftex-label-regexps') to

  "\\[[^][]*\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?"

(the stuff after \\<label has been there before, too) which works again
in the sense it matches keyval style labels but unfortunately also
causes the stack overflow.

Bye,
Tassilo