Skip to content
Tcl Source Code History Of Ticket ed29806ba
Login

History Of Ticket ed29806ba

Artifacts Associated With Ticket ed29806ba

  1. Ticket change [99e07e28d1] (rid 182651) by dgp on 2020-04-27 19:05:44:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      When iterating through a counted (not NUL-terminated) UTF-8 string via calls to
      Tcl_UtfToUniChar(), an important issue is how to keep operations from running
      past the memory approved for use.  Failure to do this might involve transgressing
      memory boundaries, or it might involve reading and acting on uninitialized bits
      found in memory the caller was never given permission to read.
      
      The algorithm embedded in several places in Tcl is to make use of
      Tcl_UtfCharComplete() to check whether a call to Tcl_UtfToUniChar() is
      safe to make with a given number of bytes left in the string.  One key
      invariant that these algorithms rely on is that Tcl_UtfCharComplete(p, n)
      will return true whenever n >= TCL_UTF_MAX.  Callers make use of this
      invariant.  They skip making the Tcl_UtfCharComplete() call that they
      already know will return true, and save those calls only for the tail end
      of the string when there are (TCL_UTF_MAX - 1) or fewer bytes left.
      
      The consequence is that Tcl_UtfToUniChar() should never read more than
      TCL_UTF_MAX bytes.  Starting in Tcl 8.6.10 it is doing so.  When p points to
      a byte in the range 0xF0 - 0xF7, the memory p[3] is read. This eliminates
      the coding guarantee that these iteration tasks are relying on.
      
      These algorithms are in Tcl itself.  There was one in Tcl_NumUtfChars, which
      led to the failure of test utf-4.11 (new since the 8.6.10 release).  The
      Tcl_NumUtfChars routine has been revised on the core-8-6-branch tip to work
      around this broken contract, but that's not a reasonable answer that can be given
      to extensions broken by a patch release change in a public routine.
      
      These algorithms are also in the encoding machinery of channels.  It should
      not be difficult to cook up a demonstration case where this change will
      corrupt the buffer management there, or at least a scenario where mem debug
      or valgrind runs of Tcl will report troubles.
      
      I'm not looking for a quick fix here.  I know this is a difficult issue enmeshed
      in work toward very important new functionality, and toward making Tcl begin
      to offer correctness in string processing that has been missing a long time.
      I'll keep my efforts at a resolution in a feature branch until they can get review.
      
    5. foundin initialized to: "8.6.10"
    6. is_private initialized to: "0"
    7. login: "dgp"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Important"
    11. status initialized to: "Open"
    12. submitter initialized to: "dgp"
    13. subsystem initialized to: "44. UTF-8 Strings"
    14. title initialized to: "Tcl_UtfToUniChar reads more than TCL_UTF_MAX bytes"
    15. type initialized to: "Bug"
  2. Ticket change [0c49068132] (rid 182834) by jan.nijtmans on 2020-04-30 12:23:33:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Not a 100% fix yet, but some improvement is possible without disturbing anything. Most code in Tcl_UtfToUniChar() is just validity checks, checking if src[3] is valid is just one of them. We can do the validity check for src[3] after all other validity checks that can be done on src[0], src[1] and src[2]. At least, the probability that this leads to a crash (however small already) becomes even smaller.
      
      B.T.W.: Tcl 8.7 (the core-8-branch) has the same issue!
      
      This is not all, more can be said about it. This first paritial fix is done in commit [98f53342750c9020], but I will come back to this issue later.
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  3. Ticket change [00598a6406] (rid 182925) by jan.nijtmans on 2020-05-01 15:14:31:

    1. icomment:
      First part of fix committed now to core-8-6-branch, core-8-branch and trunk (done differently on 8.6 compared to 8.7/9.0 due to TIP #389).
      
      Keeping open, because there are a lot other calls to Tcl_UtfToUniChar() in the code. They all are suspicious, and should posibly be replaced by TclUtfToUCS4(). There is now a utility macro TclUCS4Complete() that can protect TclUtfToUCS4() against overflow. (naming could be better .... ideas?)
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  4. Ticket change [d5cc95398c] (rid 183379) by jan.nijtmans on 2020-05-13 18:30:46:

    1. icomment:
      Fixed now in core-8-6-branch. Most Tcl_UtfToUniChar() calls in the core are replaced now by Tcl_UtdToUCS4(), and protection by Tcl_UtfCharComplete() has been verified. I believe I got all of it correct now.
      
      So, changed to Pending/Fixed. Please verify.
      
      For TCL_UTF_MAX> 3 there has not decided yet how Tcl_UtfPrev()/Tcl_UtfNext() should behave. I assumed TIP #575 behavior, which is not approved yet , neither implemented in core-8-branch. So, there's more work to do for 8.7. I suggest to keep the behavior for TCL_UTF_MAX>3 in core-8-6-branch as-is, so we have a reference to compare with. As soon as TIP #575 is accepted and everything implemented accordingly in core-8-branch, the behavior can be backported to 8.6 with TCL_UTF_MAX>3.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Fixed"
    5. status changed to: "Pending"
  5. Ticket change [be576040b0] (rid 188509) by jan.nijtmans on 2020-11-10 20:43:34:

    1. icomment:
      @dgp. Noting this commit: [87d6d589a62387d3], it looks like you are reviewing this ticket's solution in core-8-6-branch. Am I right?
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  6. Ticket change [ae596ae018] (rid 200234) by jan.nijtmans on 2022-04-18 17:34:16:

    1. closedate changed to: "2459688.23213497"
    2. closer changed to: "jan.nijtmans"
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
    5. status changed to: "Closed"