Tcl Source Code

View Ticket
Login
Ticket UUID: b5777d3d3290348abc980027a96607ccfe4bf4da
Title: Crash corner-case in TIP #502 implementation
Type: Bug Created on: 2020-08-25 16:03:24
Submitter: jan.nijtmans Assigned to: dgp
Subsystem: 13. Index Object Severity: Minor
Priority: 5 Medium Last modified: 2026-10-22 17:19:39
Status: Closed Closed by: serhiy.storchaka
Resolution: Fixed Closed on: 2026-10-21 11:09:22
Version: 8.7
Description:

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?

User Comments:
jan.nijtmans added on 2020-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.


dgp added on 2020-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.

dgp added on 2020-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.

dgp added on 2020-09-02 17:03:52:
Similar issue was addressed in 

https://core.tcl-lang.org/tcl/tktview/3138178

jan.nijtmans added on 2020-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.


dgp added on 2020-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.storchaka added on 2026-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.