postgresql/src
Tom Lane 538b3b8b35 Improve memory-usage accounting in regular-expression compiler.
This code previously counted the number of NFA states it created, and
complained if a limit was exceeded, so as to prevent bizarre regex patterns
from consuming unreasonable time or memory.  That's fine as far as it went,
but the code paid no attention to how many arcs linked those states.  Since
regexes can be contrived that have O(N) states but will need O(N^2) arcs
after fixempties() processing, it was still possible to blow out memory,
and take a long time doing it too.  To fix, modify the bookkeeping to count
space used by both states and arcs.

I did not bother with including the "color map" in the accounting; it
can only grow to a few megabytes, which is not a lot in comparison to
what we're allowing for states+arcs (about 150MB on 64-bit machines
or half that on 32-bit machines).

Looking at some of the larger real-world regexes captured in the Tcl
regression test suite suggests that the most that is likely to be needed
for regexes found in the wild is under 10MB, so I believe that the current
limit has enough headroom to make it okay to keep it as a hard-wired limit.

In connection with this, redefine REG_ETOOBIG as meaning "regular
expression is too complex"; the previous wording of "nfa has too many
states" was already somewhat inapropos because of the error code's use
for stack depth overrun, and it was not very user-friendly either.

Back-patch to all supported branches.
2015-10-16 15:55:59 -04:00
..
backend Improve memory-usage accounting in regular-expression compiler. 2015-10-16 15:55:59 -04:00
bin -- email subject limit ----------------------------------------- 2015-10-13 18:25:32 -04:00
common pgindent run for 9.5 2015-05-23 21:35:49 -04:00
include Improve memory-usage accounting in regular-expression compiler. 2015-10-16 15:55:59 -04:00
interfaces Fix order of arguments in ecpg generated typedef command. 2015-10-16 17:29:05 +02:00
makefiles Remove support for Unix systems without the POSIX signal APIs. 2015-08-31 12:56:10 -04:00
pl Fix hstore_plpython test when python3 is used. 2015-10-04 22:29:03 +02:00
port Remove support for Unix systems without the POSIX signal APIs. 2015-08-31 12:56:10 -04:00
template Attempt to work around a 32bit xlc compiler bug from a different place. 2015-08-08 01:19:02 +02:00
test Fix regular-expression compiler to handle loops of constraint arcs. 2015-10-16 15:55:58 -04:00
timezone Update time zone data files to tzdata release 2015g. 2015-10-02 19:15:39 -04:00
tools Correct pg_indent to pgindent in various comments. 2015-10-08 12:27:54 -04:00
tutorial Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
.gitignore
DEVELOPERS
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Make prove_installcheck remove the old log directory, if any. 2015-10-11 20:36:07 -04:00
Makefile.shlib AIX: Link TRANSFORM modules with their dependencies. 2015-07-15 21:00:26 -04:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00