Artifacts Associated With Ticket 3564735fffffffffffffffffffffffffffffffff
Ticket change [18868b2f61] (rid 122674) by bgriffin on 2012-09-04 15:38:00:
- assignee initialized to: "msofer"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I've recently tracked down a crash that was due to faulty coding in an incrTcl methods, however, I don't know if this is a known "problem" with incrTcl, or a bug in the 8.5.8+34 combination, or just the way things are. I'm also wondering if there shouldn't be a runtime check for this condition. So what is the problem? itcl::class Dog { variable bite method bark {} } itcl::body Dog::bark {} { variable bite set bite false puts "Bark!" } The crash is due to the unnecessary "variable" statement in the itcl::body. It ends up corrupting the heap. (Thanks for TCL_MEM_DEBUG!) $ tclsh8.5 % package require Itcl 3.4 % memory validate on % itcl::class Dog { variable bite method bark {} } % itcl::body Dog::bark {} { variable bite set bite false puts "Bark!" } % Dog fido fido % fido bark hi guard byte 0 is 0x62 b total mallocs 114496 total frees 103026 current packets allocated 11470 current bytes allocated 482362 maximum packets allocated 15640 maximum bytes allocated 630832 high guard failed at 81ba7f8, .../tcl/unix/../generic/tclHash.c 344 8 bytes allocated at (.../incrTcl/itcl/generic/itcl_migrate.c 130) Memory validation failure Abort(coredump) - foundin initialized to: "obsolete: 8.5.12"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "bgriffin"
- subsystem initialized to: "21. [namespace]"
- title initialized to: "Tcl8.5 + incrTcl3.4 [variable] crash"
- type initialized to: "Bug"
Ticket change [947e8161fc] (rid 105992) by sebres on 2012-09-04 23:13:45:
- icomment:
I could not reproduce it with 8.5.11 and itcl-3-branch on windows. How often is it reproducible?
- login: "sebres"
- mimetype: "text/plain"
- username: "sebres"
- icomment:
Ticket change [b2f1d2788e] (rid 98428) by dgp on 2012-09-05 00:07:09:
- icomment:
The failure has been present since the Tcl checkin http://core.tcl.tk/tcl/ci/c49c117219 which is "modifs to help itcl adapt to VarReform" For many Tcl checkins prior to that, current Itcl source either cannot build or cannot [load]. Appears that this bug is an indication that some details of adjusting to Tcl "VarReform" just never got done right.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [dbbde8f55b] (rid 108011) by dgp on 2012-09-05 00:11:57:
- icomment:
Rolling back Itcl to the same era, http://core.tcl.tk/itcl/info/3f5de3c16d the same problem is present. This is not a recent Itcl regression.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [eed6ce32a9] (rid 108888) by dgp on 2012-09-05 00:21:25:
- icomment:
On the bright side, whatever the problem is has apparently been resolved in Itcl 4.0b8. No troubles there.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7180286866] (rid 100687) by msofer on 2012-09-05 02:50:58:
- icomment:
Don: could you please check one rev back for itcl, ie [8d02855363]? That one should compile ok against 8.5 headers. I'm trying to check if it isn't something that I introduced when doing the unholy adaptation for compiling on 8.4 headers and running properly on 8.4 and 8.5
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [110474b306] (rid 95071) by dgp on 2012-09-06 02:39:19:
- icomment:
The memory corruption happens in the execution of the INST_VARIABLE instruction in tclExecute.c The "call" TclSetVarNamespaceVar(otherPtr) corrupts the memory. This is really a macro, and the expansion includes the line: ((VarInHash *)(otherPtr))->refCount++; This is actually writing one byte past allocated memory, so this tells me otherPtr points to a struct that is actually smaller in size than a VarInHash struct. I think this must be some Itcl declared struct that the Itcl custom resolvers allocate. I hope that's enough information for msofer to understand the problem at a more conceptual level and recommend a fix.
- login: "dgp"
- mimetype: "text/plain"
- priority changed to: "9 Immediate"
- username: "dgp"
- icomment:
Ticket change [f0be58c9c1] (rid 109247) by dgp on 2012-09-06 02:45:53:
- icomment:
Looks like the root of the problem is casting a pointer to a Var struct to the type of VarInHash struct, and then using it to get at extension fields that are not there. As a guess, we're simply not supposed to reach this code in this scenario? Some guard somewhere is failing in its duty?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [1140ae606d] (rid 95109) by dkf on 2012-09-06 06:19:51:
- icomment:
IIRC, the 8.5 series assumes in a few key spots that all variables are either a VarInHash or a member of the LVT. In particular, it assumes that TclObjLookupVarEx(…,TCL_NAMESPACE_ONLY,…) always returns a VarInHash (or NULL, of course). It sounds like Itcl is generating them in another way. I guess we ought to check if the VAR_IN_HASHTABLE flag is set on the otherPtr (i.e., use TclIsVarInHash(otherPtr) as the guard). One question though: should that be combined into the guard within TclSetVarNamespaceVar? Or should it be exposed in the INST_VARIABLE code? If the latter, I think TclVariableObjCmd has the identical problem. (It should be testable by invoking [variable bite] like [set v variable;$v bite], so as to defeat compilation.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [2efe6a6c44] (rid 92976) by dkf on 2012-09-06 06:22:06:
- icomment:
There's also the possibility that Itcl 3 might have the wrong flags set (i.e., setting the VAR_IN_HASHTABLE flag when it was never allocated as a VarInHash). If that's the case, it's got to be slated as an Itcl bug for the sake of our sanity.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [0d1ccab2c7] (rid 114303) by dgp on 2012-09-06 20:53:55:
- icomment:
Tcl_VariableObjCmd() suffers the same problem. The (Var *) returned by TclObjLookupVarEx has a flags field of 0.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [03509558db] (rid 119808) by dgp on 2012-09-06 23:08:20:
- icomment:
Here's a demonstration of a related flaw: package require Itcl itcl::class Dog { method bark {} } itcl::body Dog::bark {} { variable bite } Dog fido fido bark can't upvar from variable to itself while executing "variable bite" (object "::fido" method "::Dog::bark" body line 2) invoked from within "fido bark" These two together indicate some ways in which the Itcl custom resolvers aren't quite meeting core expectations. - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [71fb9eb0c3] (rid 100786) by dgp on 2012-09-07 02:03:06:
- icomment:
Branch bug-3564735 now contains a patch that armors Tcl against memory corruption in this scenario.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [0ae7dd885a] (rid 113901) by dgp on 2012-09-07 19:49:48:
- priority changed to: "8"
Ticket change [c5d64a1c74] (rid 121652) by dgp on 2012-09-11 21:08:39:
- closedate changed to: "2012-09-11T14:08:39"
- closer changed to: "dgp"
- icomment:
allow_comments - 1 Protection patch committed to relevant branches. Remaining problems are Itcl's and reported in the Itcl tracker.
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dgp"