* [PATCH] regex: increase the stack tre uses for tnfa creation
@ 2016-01-31 15:46 Szabolcs Nagy
2016-01-31 16:04 ` Khem Raj
0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2016-01-31 15:46 UTC (permalink / raw)
To: musl
10k elements stack is increased to 1000k, otherwise tnfa creation fails
for reasonable sized patterns: a single literal char can add 7 elements
to this stack, so regcomp of an 1500 char long pattern (with only litral
chars) fails with REG_ESPACE. (the new limit allows about < 150k chars,
this arbitrary limit allows most command line regex usage.)
ideally there would be no upper bound: regcomp dynamically reallocates
this buffer, every reallocation checks for allocation failure and at
the end this stack is freed so there is no reason for special bound.
however that may have unwanted effect on regcomp and regexec runtime
so this is a conservative change.
---
src/regex/regcomp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
index 7ce2988..da6abd1 100644
--- a/src/regex/regcomp.c
+++ b/src/regex/regcomp.c
@@ -2688,7 +2688,7 @@ regcomp(regex_t *restrict preg, const char *restrict regex, int cflags)
/* Allocate a stack used throughout the compilation process for various
purposes. */
- stack = tre_stack_new(512, 10240, 128);
+ stack = tre_stack_new(512, 1024000, 128);
if (!stack)
return REG_ESPACE;
/* Allocate a fast memory allocator. */
--
2.7.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] regex: increase the stack tre uses for tnfa creation
2016-01-31 15:46 [PATCH] regex: increase the stack tre uses for tnfa creation Szabolcs Nagy
@ 2016-01-31 16:04 ` Khem Raj
2016-01-31 16:26 ` Szabolcs Nagy
0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2016-01-31 16:04 UTC (permalink / raw)
To: musl
On Sun, Jan 31, 2016 at 7:46 AM, Szabolcs Nagy <nsz@port70.net> wrote:
> 10k elements stack is increased to 1000k,
It seems this stack is on heap is that right ?
if not then does this enforce some higher minimum limit on stack
otherwise tnfa creation fails
> for reasonable sized patterns: a single literal char can add 7 elements
> to this stack, so regcomp of an 1500 char long pattern (with only litral
> chars) fails with REG_ESPACE. (the new limit allows about < 150k chars,
> this arbitrary limit allows most command line regex usage.)
>
> ideally there would be no upper bound: regcomp dynamically reallocates
> this buffer, every reallocation checks for allocation failure and at
> the end this stack is freed so there is no reason for special bound.
> however that may have unwanted effect on regcomp and regexec runtime
> so this is a conservative change.
> ---
> src/regex/regcomp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
> index 7ce2988..da6abd1 100644
> --- a/src/regex/regcomp.c
> +++ b/src/regex/regcomp.c
> @@ -2688,7 +2688,7 @@ regcomp(regex_t *restrict preg, const char *restrict regex, int cflags)
>
> /* Allocate a stack used throughout the compilation process for various
> purposes. */
> - stack = tre_stack_new(512, 10240, 128);
> + stack = tre_stack_new(512, 1024000, 128);
> if (!stack)
> return REG_ESPACE;
> /* Allocate a fast memory allocator. */
> --
> 2.7.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] regex: increase the stack tre uses for tnfa creation
2016-01-31 16:04 ` Khem Raj
@ 2016-01-31 16:26 ` Szabolcs Nagy
0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2016-01-31 16:26 UTC (permalink / raw)
To: musl
* Khem Raj <raj.khem@gmail.com> [2016-01-31 08:04:45 -0800]:
> On Sun, Jan 31, 2016 at 7:46 AM, Szabolcs Nagy <nsz@port70.net> wrote:
> > 10k elements stack is increased to 1000k,
>
> It seems this stack is on heap is that right ?
> if not then does this enforce some higher minimum limit on stack
>
yes this is heap allocated buffer (but called and used as stack
in the tre code)
> otherwise tnfa creation fails
> > for reasonable sized patterns: a single literal char can add 7 elements
> > to this stack, so regcomp of an 1500 char long pattern (with only litral
> > chars) fails with REG_ESPACE. (the new limit allows about < 150k chars,
> > this arbitrary limit allows most command line regex usage.)
> >
> > ideally there would be no upper bound: regcomp dynamically reallocates
> > this buffer, every reallocation checks for allocation failure and at
> > the end this stack is freed so there is no reason for special bound.
> > however that may have unwanted effect on regcomp and regexec runtime
> > so this is a conservative change.
> > ---
> > src/regex/regcomp.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
> > index 7ce2988..da6abd1 100644
> > --- a/src/regex/regcomp.c
> > +++ b/src/regex/regcomp.c
> > @@ -2688,7 +2688,7 @@ regcomp(regex_t *restrict preg, const char *restrict regex, int cflags)
> >
> > /* Allocate a stack used throughout the compilation process for various
> > purposes. */
> > - stack = tre_stack_new(512, 10240, 128);
> > + stack = tre_stack_new(512, 1024000, 128);
> > if (!stack)
> > return REG_ESPACE;
> > /* Allocate a fast memory allocator. */
> > --
> > 2.7.0
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-01-31 16:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-31 15:46 [PATCH] regex: increase the stack tre uses for tnfa creation Szabolcs Nagy
2016-01-31 16:04 ` Khem Raj
2016-01-31 16:26 ` Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).