Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Large [expr]ession parse error/segfault

Closed / Fixed3e7eca8c8c70ce1b50d4feeea12bef11e26c1227Created 11 years agoUpdated 11 years ago
Descriptionplain2015-07-28 19:57:50
From RickyB98 on the chat:

% info patch
8.6.4
% set go 1; set string 3; while {$go} {incr iter; append string +4/double([incr x 2]*($x+1)*($x+2))-4/double([incr x 2]*($x+1)*($x+2)); if {$iter > 10000000} {set go 0}}; concat
% string length $string
883333447
% time {expr $string}
unbalanced close paren
in expression "...e(26843546*(26843546+1)*(26843546+2))-4/doubl..."
% exit


Original report was a segfault, and that indeed happens with Tcl 8.5.9.

On trunk and core-8-5-branch tip we get the (false) parsing error 
message instead.

Initial guess is that we're overflowing something or other.
Referenced by4
dgpplain2015-07-28 21:14:13
Initial debugging shows the bad parse taking place
when the size of the nodes array is 268435456.

Since the OpNode struct seems to be of size 32 bytes,
that does seem to indicate we're getting too big for
our ckalloc'ed britches.
dgpplain2015-07-29 10:06:17
Overflow of allocation size repaired.

Believe that's all of the problem, but hard to say since
once parsing is repaired, that expression doesn't compute
in less than hours.  Quite possible days or even much much more.
sebresplain2015-07-29 10:48:04
Are you sure, really?

If I look at this code - I see an endless cycle if size > UINT_MAX/sizeof(OpNode) ...

```
	    OpNode *newPtr = NULL;

	    do {
	      if (size <= UINT_MAX/sizeof(OpNode)) {
		newPtr = (OpNode *) attemptckrealloc((char *) nodes,
			(unsigned int) size * sizeof(OpNode));
	      }
	    } while ((newPtr == NULL)
```

Regards, sebres
sebresplain2015-07-29 11:10:40
Sorry, was my mistake, I have missed a line bottom, that belong this cycle also:

&& ((size -= (size - nodesUsed) / 2) > nodesUsed));

Thus is alright and ticket closed.
dgpplain2015-07-29 12:47:56
It appears that my "days to calculate" observation came
from doing the testing on a system starved for memory.

Now on a better resourced system, I get:

% set iter 0; set string 3; set x 0
0
% while {[incr iter] <= 7000000} {
append string +4/double([incr x 2]*($x+1)*($x+2))-4/double([incr x 2]*($x+1)*($x+2))                                                                            
}; concat     
% time {expr $string}
make: *** [shell] Segmentation fault

7M terms is enough to prompt another segfault.  Maybe compiling.
Maybe execution.
dgpplain2015-07-29 12:52:34
sorry, no.  Made an error and tested on an unpatched sandbox.
Without the patch, the error is still there!
dgpplain2015-07-29 14:31:02
The next actual failure I see is a panic unable
to allocate enough memory for an expansion of the
literal table.  

Even on a system with more memory, the literal table
limits appear to be reached with this example.
dgp Closed ticket [3e7eca8c8c]. [History diff]2015-07-29 14:55:55
Log in (anonymous is fine) to add a comment.