Skip to content
Tcl Source Code History Of Ticket da63e4c1e
Login

History Of Ticket da63e4c1e

Artifacts Associated With Ticket da63e4c1e

  1. Ticket change [19f5803f9e] (rid 206894) by anonymous on 2022-11-16 10:16:13:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. 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
      
    5. foundin initialized to: "9.0a4"
    6. is_private initialized to: "0"
    7. login: "anonymous"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "ef1993a98c1daa778fe0b246a7af12b3076f2240"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "anonymous"
    14. subsystem initialized to: "12. ByteArray Object"
    15. title initialized to: "Crash in"
    16. type initialized to: "Bug"
  2. Ticket change [daf3a44a9a] (rid 206895) by jan.nijtmans on 2022-11-16 10:49:35:

    1. assignee changed to: "jan.nijtmans"
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
    4. title changed to: "Crash in Tcl_WriteChars()"
  3. Ticket change [c3514056b9] (rid 207228) by jan.nijtmans on 2022-11-23 07:56:44:

    1. assignee changed to: "dgp"
    2. 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
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  4. Ticket change [4f13e77294] (rid 207229) by anonymous on 2022-11-23 08:53:24:

    1. 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
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  5. Ticket change [2af3ced5a9] (rid 207234) by anonymous on 2022-11-23 09:38:36:

    1. 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.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  6. Ticket change [7ff07324bd] (rid 207246) by jan.nijtmans on 2022-11-23 15:34:14:

    1. 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.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  7. Ticket change [1a6a733564] (rid 207280) by anonymous on 2022-11-23 18:04:57:

    1. icomment:
      I've just tested the change in Tcl_WriteChars(), and this works fine for NaviServer.
      
    2. login: "anonymous"
    3. mimetype: "text/plain"
  8. Ticket change [3cbd8aecbc] (rid 207300) by jan.nijtmans on 2022-11-23 21:26:26:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Fix committed [3539aef815|here]. Leaving this ticket pending for possible further enhancements.
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
    5. resolution changed to: "Fixed"
    6. status changed to: "Pending"
  9. Ticket change [3ab6d62437] (rid 207509) by jan.nijtmans on 2022-11-28 23:13:41:

    1. closedate changed to: "2459912.46784431"
    2. closer changed to: "jan.nijtmans"
    3. 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.
      
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
    6. status changed to: "Closed"