segfault after regexp

John W. Eaton jwe at bevo.che.wisc.edu
Sat Oct 11 08:09:24 CDT 2008


On 11-Oct-2008, Thomas Weber wrote:

| On Sat, Oct 04, 2008 at 11:40:04AM +0200, Thomas Weber wrote:
| > Well, quoting pcrestack's man page:
| > "As a very rough rule of thumb, you should reckon on about 500 bytes per
| > recursion. Thus, if you want to limit your stack usage to 8Mb, you
| > should set the limit at 16000 recursions. A 64Mb stack, on the  other
| > hand,  can support around 128000 recursions. The pcretest test program
| > has a command line option (-S) that can be used to increase the size of
| > its stack."
| > 
| > So, we have some estimates, with a security factor of (say) 2, we should
| > be alright. 
| > 
| > This doesn't address the important question though: what kind of memory
| > limit do we pose on the stack?
| 
| Patch attached. I assume a maximum of 500MB on the stack (if there's no
| hard limit), with a safety factor of 2.

I don't think getrlimit and setrlimit are portable, so at a minimum,
you'll need a configure check and only use this method if thse
functions are available.

But is this really the right place for the fix?  Or even the right
approach to take?  Octave is not the only program using PCRE that
might run into this problem.  It seems to me that it would be better
to fix it in PCRE itself, preferably by using a different algorithm
that doesn't suffer from these problems.  Modifying the stack limit
does not seem like a real fix to the actual problem.  Instead, you are
just hiding it.  The problem still exists, and will still bite for
larger problems or more complex data.

jwe


More information about the Bug-octave mailing list