Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [b5777d3d32] Crash corner-case in TIP #502 implementation status stil... artifact: 0a3ce2550e user: serhiy.storchaka
2026-10-21
11:09 • Closed ticket [b5777d3d32]. artifact: 2903d3ec49 user: serhiy.storchaka
2020-09-16
14:24 • Ticket [b5777d3d32]: 3 changes artifact: e86817d5a2 user: dgp
06:20 • Pending ticket [b5777d3d32]. artifact: 5b1bf1178d user: jan.nijtmans
2020-09-15
14:48
Fix [b5777d3d32]: Crash corner-case in TIP #502 implementation check-in: fca1a2a297 user: jan.nijtmans tags: core-8-branch
2020-09-02
17:03 • Ticket [b5777d3d32] Crash corner-case in TIP #502 implementation status stil... artifact: 097ece2ce4 user: dgp
16:25 • Ticket [b5777d3d32]: 3 changes artifact: 1088c6e473 user: dgp
2020-09-01
22:28 • Ticket [b5777d3d32]: 3 changes artifact: 089887a8f0 user: dgp
2020-08-25
16:15 • Ticket [b5777d3d32]: 3 changes artifact: 63ce3b37e5 user: jan.nijtmans
16:12 • Ticket [b5777d3d32]: 4 changes artifact: a3e4a6a59d user: jan.nijtmans
16:09
Add test-case util-9.59, which demonstrates bug [b5777d3d32] check-in: f1fba2e12f user: jan.nijtmans tags: bug-b5777d3d32
16:03 • New ticket [b5777d3d32] Crash corner-case in TIP #502 implementation. artifact: ae15e72c63 user: jan.nijtmans

Crash corner-case in TIP #502 implementation

Closed / Fixedb5777d3d3290348abc980027a96607ccfe4bf4daCreated 6 years agoUpdated 41 days ago
Descriptionwiki2020-08-25 16:03:24
Try the following:
$tclsh8.7
% string index abcd 0-0x10000000000000000
% 
tailcall cannot find the right splicing spot: should not happen!
Abort trap: 6

(press "enter" twice after typing the command).

I could re-produce this both on Windows 10 and on MacOS.

Bisection shows that this crash is already happening since commit [bae05b9e6f], which is the TIP #502 implementation. Before that, the result was the same as in Tcl 8.6:

$ tclsh8.6
% string index abcd 0-10000000000000000
bad index "0-10000000000000000": must be integer?[+-]integer? or end?[+-]integer?
Referenced by2
jan.nijtmanswiki2020-08-25 16:12:01

Branch [bug-b5777d3d32] contains a test-case for this bug.

Even though it's a corner-case very unlikely to be encounter by anyone (but ... I did ... by pure chance ...), it's a crash waiting to happen.

jan.nijtmans Ticket [b5777d3d32]: 3 changes [History diff]2020-08-25 16:15:03
dgpplain2020-09-01 22:28:23
Fix committed to the bug fix branch to solve the reported problem, but
not the deeper brokenness that underlies it.
dgpplain2020-09-02 16:25:10
More direct fix is in dgp-nested-execution.

Something like this may need to be done in many other places in the
bytecode execution engine for full safety against re-entry into the
execution engine.
dgpplain2020-09-02 17:03:52
Similar issue was addressed in 

https://core.tcl-lang.org/tcl/tktview/3138178
jan.nijtmanswiki2020-09-16 06:20:53

I'm wondering if the stack protection isn't really overkill here. How much performance does it cost in the normal case? Therefore keeping open for now. The bug-b5777d3d32 branch undoes the stack protection changes and simply uses a separate interpreter for this case always.

Or .. maybe .. just parse the two parts as bigintegers and add/subtract them using libtommath's functions.

dgpplain2020-09-16 14:24:10
Any of those approaches will work.  I don't object to any of them.  All have
their pros and cons.

The broader issue is that we have this point of fragility in the execution
engine.  Any function call out of TEBCresume that could possibly lead
to nested bytecode execution is at risk without this protection.  That set of
routines isn't stable as development continues.  Anything that permits 
extension callbacks should get protection, and with customizable traces and
resolvers, there are many paths that can potentially do that. A "no compromise
on safety" approach would protect every call, or at least every call that
passes interp as an argument.

The (DE)CACHE_STACK_INFO macros themselves are tiny.  Maybe I am missing
something, but the main effect of them seems to be that they force the more
expensive implementation of the INST_START_CMD instruction.
serhiy.storchakawiki2026-10-21 11:09:22

The crash was fixed in 9.0.0 by [fca1a2a297], with test util-9.59 (passes on trunk and 9.0). 8.6 is not affected, since TIP #502 is 8.7+. The broader question of protecting other re-entry points of the bytecode engine (see branch dgp-nested-execution) can get a ticket of its own if someone wants to pursue it.

serhiy.storchaka Ticket [b5777d3d32]: 3 changes [History diff]2026-10-22 17:19:39
Log in (anonymous is fine) to add a comment.