Artifacts Associated With Ticket da63e4c1e
Ticket change [19f5803f9e] (rid 206894) by anonymous on 2022-11-16 10:16:13:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- comment initialized to:
Tcl 9.0 crashes in Tcl_WriteChars() when calling TclDecrRefCount(copy) (in generic/tclIO.c). Before the crash, the Tcl_Obj *copy has the following content: copy refcount 0 copy bytes 0x0 copy type 0x1054c77a0 copy type name bytearray The problem happens in [1] and can be reproduced when compiling the tip version of NaviServer with Tcl9.0 and running then "make test". Adding "Tcl_IncrRefCount(copy)" after TclNarrowToBytes() helps for NaviServer to get past Tcl_WriteChars(), but does not solve the problem (as pointed out by Jan). -gustaf [1] https://bitbucket.org/naviserver/naviserver/src/c7b93582c076c41508dc7bf342d3fa864d3d6409/nsd/pidfile.c#lines-65
- foundin initialized to: "9.0a4"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "ef1993a98c1daa778fe0b246a7af12b3076f2240"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "12. ByteArray Object"
- title initialized to: "Crash in"
- type initialized to: "Bug"
Ticket change [daf3a44a9a] (rid 206895) by jan.nijtmans on 2022-11-16 10:49:35:
- assignee changed to: "jan.nijtmans"
- login: "jan.nijtmans"
- mimetype: "text/plain"
- title changed to: "Crash in Tcl_WriteChars()"
Ticket change [c3514056b9] (rid 207228) by jan.nijtmans on 2022-11-23 07:56:44:
- assignee changed to: "dgp"
- icomment:
See also [07563f771]. My guess is that this is introduced with [https://core.tcl-lang.org/tips/doc/trunk/tip/568.md|TIP #568]: Revise ByteArray Routines To Support Proper Value Extraction
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [4f13e77294] (rid 207229) by anonymous on 2022-11-23 08:53:24:
- icomment:
Hmm, the buffer passed to Tcl_WriteChars() does not look problematic to me: [23/Nov/2022:09:51:05][14150.102ae4580][-main:conf-] Notice: buffer for Tcl_WriteChars (len 6): 31 34 31 35 30 0a
- login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [2af3ced5a9] (rid 207234) by anonymous on 2022-11-23 09:38:36:
- icomment:
The problem seems to be, that after objPtr = Tcl_NewStringObj(src, len); copy = TclNarrowToBytes(objPtr); objPtr and copy point to the same Tcl_Obj, and that after the TclDecrRefCount in src = (char *) Tcl_GetByteArrayFromObj(copy, &len); TclDecrRefCount(objPtr); also the object pointed to by copy is cleared, such that the final TclDecrRefCount(copy); causes the crash. So, it looks to me, that either adding one Tcl_IncrRefCount() or removing one of the TclDecrRefCount() solves the issue. TclNarrowToBytes() seems to return always the same object, or removing the first TclDecrRefCount(objPtr) seems ok. - login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [7ff07324bd] (rid 207246) by jan.nijtmans on 2022-11-23 15:34:14:
- icomment:
First attempt for a fix [58883dde6de7f4a8|here]. Although the fix works, it shows that TIP #601 (about making encoding errors thowing exceptions) was not implemented throughout yet. For example, testcase io-1.6 does the following: <pre> fconfigure $f -encoding binary puts -nonewline $f "a乍\x00" </pre> This is illegal, because the "binary" encoding only accepts bytes while 乍 is not a byte at all. With TIP #601, I expect this test-case to throw an exception. The solution [58883dde6de7f4a8] does this by generating this exception when converting the string to a bytearray. What would be even better, is when "puts" would write the bytes to the channel up to the error-character (so, just 'a' in this case), and then throw the exception. That part is not done yet in this first attempt. - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [1a6a733564] (rid 207280) by anonymous on 2022-11-23 18:04:57:
- icomment:
I've just tested the change in Tcl_WriteChars(), and this works fine for NaviServer.
- login: "anonymous"
- mimetype: "text/plain"
- icomment:
Ticket change [3cbd8aecbc] (rid 207300) by jan.nijtmans on 2022-11-23 21:26:26:
- assignee changed to: "jan.nijtmans"
- icomment:
Fix committed [3539aef815|here]. Leaving this ticket pending for possible further enhancements.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Pending"
Ticket change [3ab6d62437] (rid 207509) by jan.nijtmans on 2022-11-28 23:13:41:
- closedate changed to: "2459912.46784431"
- closer changed to: "jan.nijtmans"
- icomment:
At first sight, the use of TclNarrowToBytes() looked suspicious. Currently there's only one usage left (in "binary format"), and there it's doing exactly the right thing. Maybe not the most efficient way, but that's not enough to leave this ticket open for. So, closing this ticket.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"