Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-11
10:09 • Ticket [1905562fff] test reg-33.14 gets pointer smash status still Open with... artifact: 22fe20aef0 user: serhiy.storchaka
2013-09-09
09:52 • Ticket [1905562fff]: 5 changes artifact: 787e6f198d user: dkf
2013-08-30
17:04 • Ticket [1905562fff]: 3 changes artifact: 233f1c28ad user: dgp
2013-08-01
19:25 • Ticket [1905562fff]: 4 changes artifact: c8148b8a3d user: dgp
19:18
[1905562] [8d2c0da36d] Raise the recursion limits on regexps to allow existing regexps "in the wild"... check-in: b7100ded1f user: dgp tags: trunk
19:10 • Ticket [1905562fff] test reg-33.14 gets pointer smash status still Open with... artifact: b3df8b11cd user: dgp
17:50 • Ticket [1905562fff]: 3 changes artifact: c69dbc9b88 user: dgp
17:48 • Ticket [1905562fff]: 3 changes artifact: 30e11dbfec user: dgp
17:38 • Ticket [1905562fff]: 3 changes artifact: 835befc0da user: dgp
17:19 • Ticket [1905562fff]: 7 changes artifact: b095d8ad07 user: dgp
2013-04-01
23:20 • Open ticket [1905562fff]. artifact: 567ae43d80 user: dgp
2013-02-07
00:52 • Ticket [1905562fff]: 4 changes artifact: 0da0e89ccc user: dgp
2008-07-16
09:20 • Closed ticket [1905562fff]. artifact: b428e2e392 user: sf-robot
2008-07-01
21:31 • Pending ticket [1905562fff]. artifact: 7acf6c9c16 user: dkf
2008-06-28
20:38 • Ticket [1905562fff]: 5 changes artifact: 129eb355c5 user: msofer
2008-03-19
21:46 • Ticket [1905562fff]: 4 changes artifact: 41d1ee9731 user: dkf
21:07 • Ticket [1905562fff]: 2 changes artifact: b0c4ff68cc user: dgp
21:07 • Ticket [1905562fff]: 4 changes artifact: 5812767c3a user: dgp
20:41 • Ticket [1905562fff]: 7 changes artifact: 7f16e39d9d user: dkf
19:51 • Ticket [1905562fff]: 5 changes artifact: db5fddff9d user: kennykb
04:57 • Ticket [1905562fff]: 1 change artifact: ddd02423c2 user: dgp
04:57 • Ticket [1905562fff]: 4 changes artifact: 6661c56d32 user: dgp
04:36 • Ticket [1905562fff]: 4 changes artifact: 3864b67662 user: dgp
04:07 • Ticket [1905562fff]: 4 changes artifact: 386cd826c0 user: dgp
00:27 • Ticket [1905562fff]: 4 changes artifact: d4d072f294 user: dgp
2008-03-15
02:26 • Ticket [1905562fff]: 4 changes artifact: 4387665c47 user: cleverly
2008-03-12
02:09 • Ticket [1905562fff]: 4 changes artifact: cd73bc9ed5 user: dgp
2008-03-02
11:23 • Ticket [1905562fff]: 4 changes artifact: bd1b6d6557 user: kennykb
03:57 • New ticket [1905562fff]. artifact: 90ab2f848b user: kennykb

test reg-33.14 gets pointer smash

Open1905562fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 53 days ago
Descriptionplain2008-03-02 03:57:14
Running a self-built TCL from today's HEAD, I get a segmentation violation at reg-33.14.  The build was with
msys and MSVC 2k5 with

CC=cl path/to/win/configure --enable-symbols --enable-threads

More details when I've got 'em.
kennykbplain2008-03-02 11:23:07
Logged In: YES 
user_id=99768
Originator: YES

The crash appears to be related to a stack overflow, heap corruption, or memory exhaustion in the duptraverse() function in regc_nfa.c.  Running without the MSVC debugger, there is a simple pointer smash.  Launching the executable under the debugger, and running from there, yields instead a call to Tcl_Panic with "unable to allocate 368 bytes" at line 1032.  The recursive nest of calls to duptraverse is beyond MSVC's ability to traverse.
dgpplain2008-03-12 02:09:00
Logged In: YES 
user_id=80530
Originator: NO


any progress on this?
cleverlyplain2008-03-15 02:26:14
Logged In: YES 
user_id=22080
Originator: NO

As a point of reference, with 8.5.2rc1 reg-33.14 also segfaults on OpenBSD 4.2 (sparc64) in a non-thread enabled build (gcc 3.3.5).
dgpplain2008-03-19 00:27:18
Logged In: YES 
user_id=80530
Originator: NO


Reproduced on sparc Solaris 9 with a
--enable-symbols --enable-64bit configuration.
dgpplain2008-03-19 04:07:24
Logged In: YES 
user_id=80530
Originator: NO


Going back a few releases...

$ make runtest
...
% info patch
8.4.15
% regexp {(x{200}){200}$y} x
Segmentation Fault


The test that triggers the crash
is new.  The bugginess that permits
the crash is apparently not.
dgpplain2008-03-19 04:36:50
Logged In: YES 
user_id=80530
Originator: NO


This is looking like C stack overflow.
dgpplain2008-03-19 04:57:29
Logged In: YES 
user_id=80530
Originator: NO


On a platform where test reg-33.14
does not crash, I see:

% regexp {(x{222}){222}$y} x
couldn't compile regular expression pattern: nfa has too many states

So if things continue to get bigger,
this error message appears to protect against
the possibility of stack overflow everywhere.
It's assumed there's enough stack to cover traversal
of all nfa's with states below the limit.

Points to a possible fix of imposing a smaller
limit on these stack-limited platforms?

Alternative would be a significant rewrite of
the RE engine guts to not do so much recursive
stuff.

Shorter term, we can either drop the demands
of test reg-33.14 to avoid confronting the issue
in the test suite, or simply mark it as a
nonportable test.
dgp Ticket [1905562fff]: 1 change [History diff]2008-03-19 04:57:30
kennykbplain2008-03-19 19:51:53
Logged In: YES 
user_id=99768
Originator: YES

Reassigning to someone who appears to have a clue what's going on.
dkfplain2008-03-19 20:41:10
Logged In: YES 
user_id=79902
Originator: NO

Suggested workaround: use a bigger stack. Meanwhile, I've marked the test nonPortable.

Maybe the correct fix is to use stack protection voodoo like Tcl does/did. Assigning to Miguel for comment.
dgpplain2008-03-19 21:07:40
Logged In: YES 
user_id=80530
Originator: NO


Miguel's efforts at stack protection are
appreciated, but they don't exactly have
a flawless track record.

A more certain "real fix" for this issue
would be to follow the expr parser rewrite
example and replace all these recursive
routines with non-recursive versions.
dgp Ticket [1905562fff]: 2 changes [History diff]2008-03-19 21:07:41
dkfplain2008-03-19 21:46:03
Logged In: YES 
user_id=79902
Originator: NO

Hmm, it's doing tree-traversal and it needs to actions both before and after the recursive step. That's the case that's hard to convert.
msoferplain2008-06-28 20:38:02
Logged In: YES 
user_id=148712
Originator: NO

C-stack protection against too-deep Tcl recursion? I'd rather get rid of it. And I will, during 8.6a? as part of NRE. 

I imagine we could keep parts of it for regexps, but I agree with dgp (and jenglish, and many others): C-stack checking magic is a nasty hack, non-portable and half-working at best.
dkfplain2008-07-01 21:31:11
Logged In: YES 
user_id=79902
Originator: NO

Added a focussed limit. duptraverse() can now only go 500 deep, and that seems to be enough for everything in the test suite that's normally run. Let me know if that's not enough (or too much).
sf-robotplain2008-07-16 09:20:19
Logged In: YES 
user_id=1312539
Originator: NO

This Tracker item was closed automatically by the system. It was
previously set to a Pending status, and the original submitter
did not respond within 14 days (the time period specified by
the administrator of this Tracker).
dgpplain2013-02-07 00:52:58
See 3603557 for report from someone for whom
that was not enough. :)
dgpplain2013-04-01 23:20:48
Another person needing broader limits has reported
to TCLCORE.  Re-opening so that a different solution
can be considered.
dgpplain2013-08-01 17:19:51
Ticket [8d2c0da36d] is a third report on this.
Time to fix it.
dgpplain2013-08-01 17:38:48
The current trunk already has the limit
raise from 500 (in 8.6.0 release) to 700.

As luck would have it, the new stress test
derived from DejaGnu requires a value of 701,
at least on my system.
dgpplain2013-08-01 17:48:05
Another less simplified test:

https://git.lysator.liu.se/lyskom-server/lyskom-server/blobs/raw/master/src/server/testsuite/dejagnu.0/01-long-regexp.exp
dgpplain2013-08-01 17:50:58
Empirically, on my system, that one needs a limit of 817.
dgpplain2013-08-01 19:10:51
At the other end, on a Solaris 10 system where 
I can produce the stack overflow crashes, I need
a DUPTRAVERSE_MAX_DEPTH value of no more than 32639
to provide protection.

Pending further input from other platforms, I'd
suggest a better compromise limit value to permit
ridiculous regexps but still provide the stack
overflow protection would be a value of 15000.
dgpplain2013-08-01 19:25:08
Committed that value to trunk, along
with a test to keep the latest in-the-wild
regexp working.

Subject to further revision if we get even
longer regexps reported, or if we find platforms
where the new limit fails to protect against
stack smashes.
dgpplain2013-08-30 17:04:51
See Ticket 267b7e2334 for another complaint
on this subject (possibly out of date) but
with a tangible suggestion how to implement
a real solution rather than on ongoing tuning
chase.
dkfhtml2013-09-09 09:52:24

Assigning to someone who's more likely to work on this than me.

serhiy.storchakawiki2026-10-11 10:09:04

The crash is gone since the DUPTRAVERSE_MAX_DEPTH limit, but the error is still the misleading "out of memory" (see also [267b7e2334]), and reg-33.14 is still marked nonPortable.

Proposed fix in branch regexp-stack-depth (for [7d47ba7d94]): the recursive functions now check the real stack depth, so such REs fail with "regular expression is too complex" on any stack size, and reg-33.14 is a normal test again.

Log in (anonymous is fine) to add a comment.