Skip to content
Tcl Source Code History Of Ticket 1b1f5f0b53
Login

History Of Ticket 1b1f5f0b53

Artifacts Associated With Ticket 1b1f5f0b53

  1. Ticket change [bf24d4c8c7] (rid 181160) by dgp on 2020-04-03 14:58:34:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      Starting with checkin
      
      https://core.tcl-lang.org/tcl/info/aed6634d2c
      
      Tcl_UtfNext() began stepping over 4-byte UTF-8 sequences, even in
      the default configuration where TCL_UTF_MAX == 3.  This is inconsistent
      new behavior in the default build compared with prior Tcl 8.6 patch releases.
      
      One consequence is that a sequence of steps through a string with
      Tcl_UtfNext() no longer matches with the indexing of Tcl_UniCharAtIndex()
      
    5. is_private initialized to: "0"
    6. login: "dgp"
    7. priority initialized to: "5 Medium"
    8. resolution initialized to: "None"
    9. severity initialized to: "Important"
    10. status initialized to: "Open"
    11. submitter initialized to: "dgp"
    12. subsystem initialized to: "- New Builtin Commands"
    13. title initialized to: "Tcl_UtfNext incompatibility in Tcl 8.6.10"
    14. type initialized to: "Bug"
  2. Ticket change [95a31250ea] (rid 181161) by jan.nijtmans on 2020-04-03 15:29:52:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Actually, I don't think that can actually happen:  Tcl 8.6 never generates 4-byte UTF-8 sequences, it always splits them in two 3-byte UTF-8 sequences internally.
      This can only happen if an extension creates a string using Tcl_NewStringObj() which has a 4-byte UTF-8-sequences in it. Earlier Tcl versions handle this as 4 separate bytes, now Tcl tries to handle that more sensible as 2 surrogates. But not everywhere in the code that's handled correctly.
      
      Given that Tcl 8.6 is not designed to handle 4-byte UTF-8 sequences at all, it's a "unspecified behaviour".
      
      That said, I have no problem changing the
         #if TCL_UTF_MAX <= 4
      back to
         #if TCL_UTF_MAX == 4
      
      Thanks for noticing this (even though, I don't think you can actually show bad behavior using this with TCL_UTF_MAX=3). Test-case please?
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
  3. Ticket change [36dc0d376e] (rid 181162) by dgp on 2020-04-03 17:37:17:

    1. icomment:
      
      I did try making a test case, but Tcl itself makes very little use of Tcl_UtfNext().
      It is used only in the parsing of variable names searching for "(" and "::" characters,
      and whether bytes that are not those things are skipped one or four at a time does
      no harm.
      
      The impact is only going to be seen in an extension.
      
      A handful of calls are in Tk. I can check those for any scriptlevel demo that
      might be possible.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  4. Ticket change [d93bdfa2bd] (rid 181163) by dgp on 2020-04-03 17:41:40:

    1. icomment:
      
      I wish that we could say that handling of non-conformant UTF-8 sequences was "unspecified behavior".
      
      Unfortunately, Tcl's established handling of improper UTF-8 is documented.
      
      http://www.tcl-lang.org/man/tcl8.6/TclLib/Utf.htm
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  5. Ticket change [84fd2c113a] (rid 181164) by dgp on 2020-04-03 18:48:45:

    1. icomment:
      
      It will take considerable effort to get a final demo, but it looks like
      [selection get] with a [selection handle] in place and the wrong values
      in the right places are at risk of trouble.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  6. Ticket change [3060cc90b3] (rid 181185) by jan.nijtmans on 2020-04-05 21:07:24:

    1. icomment:
      I think the documentation should be adapted, explaining why 4-byte sequences are still considered "invalid" in Tcl 8.6, but still are handled internally as if they are formed by 2 surrogates ....  I'll work on that.
      
      Tcl_UtfNext() stepping over 4 bytes is "least surprising" behavior. I don't see how it could cause a problem, given that 4-byte UTF-8 sequences still are "illegal" in 8.6. Stepping over individual bytes (as older Tcl 8.6 releases do) is not usefull behavior at all, I think the complaints on that are valid, even though it - indeed - doesn't match the current documentation.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  7. Ticket change [538c33befb] (rid 181857) by jan.nijtmans on 2020-04-16 20:06:59:

    1. icomment:
      According to the new documentation in Tcl 8.5:
      
          *In any other circumstance, Tcl_UtfNext returns \fIsrc\fR+1*
      
      That's not according to the original definition of Tcl_UtfNext, and causing an incompatibility!  I'll try to come up with a testcase.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  8. Ticket change [72afdac540] (rid 181862) by jan.nijtmans on 2020-04-16 20:31:31:

    1. icomment:
      Testcase added here: [fd345b2af33581fb].   This has always been wrong, BTW, so (contrary what I wrote before) it is not causing an incompatibility. The new implementation in 8.5 still does it wrong the same way. (Adapting the documentation to conform with the current implementation is too easy ....)
      
      Since Tcl never sets the pointer to the 2nd byte of a 3-byte sequence, I don't think this causes any problem. But if we want Tcl_UtfNext() to behave 100% as originally intended, the we might as well correct this too.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [a1c0d6ee9f] (rid 181878) by dgp on 2020-04-16 21:14:12:

    1. icomment:
      
      Given the interface restriction, when Tcl_UtfNext gets the argument src,
      it cannot know whether it is safe to attempt to read src[-1].
      
      If src points to a trail byte, and we cannot read src[-1] and so on, there's
      no way to know whether we're on the 2d or 3d or 4th trail byte or just
      pointing to some malformed garbage we still haven't fully outlawed.
      
      Either we do the minimal thing which is step one byte forward always, (current answer,
      and the answer we've had in place for 20 years)
      or alternatively we could scan forward up to TCL_UTF_MAX-1 bytes and
      seek out the first non-trail byte, which would make the new test happier,
      but might introduce some synchronization troubles with other assumptions.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  10. Ticket change [eaaede2d91] (rid 181918) by dgp on 2020-04-17 03:30:08:

    1. icomment:
      
      The documentation for Tcl_UtfAtIndex(index) has always described it
      to be "...equivalent to calling Tcl_UtfNext index times."
      
      When Tcl_UtfNext was changed so that a single call could step over a
      four-byte sequence, but Tcl_UtfAtIndex counts indices as if each one
      labels a UCS-2 code unit in a UTF-16 representation, that guarantee was
      broken.
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  11. Ticket change [cd40edafa2] (rid 181960) by jan.nijtmans on 2020-04-17 10:49:33:

    1. icomment:
      In commit [7f56d3c4b18e9c6c] you made the following change:
      
      [https://core.tcl-lang.org/tcl/fdiff?v1=9b3899b2c5ede87f&v2=5f0549e85e71537a]
      
      Do you want me to explain why "\xF4\x90\x80\x80" is an invalid byte sequence, so it's string length should be 4?  Or did you figure that out by now? I think it's the last regression in your implementation I'm aware of.
      
      Testcase utf-6.88 shows a long-standing bug IMHO. I'll come back on that later.
      
      My congratulations on the Tcl_Prev()/Tcl_Next() reform: It looks mostly correct now. I don't agree on the documentation change, and there are still 1 or 2 minor corner-cases which are not correct, but we are getting there...
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  12. Ticket change [419149266c] (rid 182001) by dgp on 2020-04-17 14:35:52:

    1. icomment:
      
      I agree that the documentation is a work in progress. When the timeline of
      what is changing and when and why is clear, we'll get better language that
      is both accurate and that points the way through the journey.
      
      Should we open a fresh ticket to hash out how Tcl_UtfNext should
      act when its argument points to a trail byte?
      
      I don't understand the question about test utf-2.11
      It is effectively the same test as utf-2.8 .  It has the same expected result.
      What's the confusion?
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  13. Ticket change [7bcb34ef97] (rid 182006) by dgp on 2020-04-17 15:34:19:

    1. icomment:
      
      New tickets: [493dccc2de] [27944a3661]
      
    2. login: "dgp"
    3. mimetype: "text/plain"
  14. Ticket change [bf8539bf21] (rid 182007) by jan.nijtmans on 2020-04-17 15:34:39:

    1. icomment:
      > I don't understand the question about test utf-2.11
      > It is effectively the same test as utf-2.8
      
      No, it's not! In utf-2.8, the byte sequence is "\xF0\x90\x80\x80" which translates to Unicode character \U10000, which is perfectly valid. In contrast, utf-2.11, "\xF4\x90\x80\x80", would translate to Unicode character \U110000.  But the maximum Unicode character defined is \U10FFFF, so it's too big. This algorithm, checking the validity of over-long 4-byte sequences is correctly implemented in Tcl_UtfToUniChar(), but it's not correctly implemented in Tcl_UtfNext() yet. I added this test-case to core-8-branch, so you can see that this really is a regression.
      
      Thanks!
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  15. Ticket change [15790418b3] (rid 182308) by jan.nijtmans on 2020-04-23 11:37:12:

    1. icomment:
      Should be fixed in [5c322bbd51d17664]. With this commit, repeated Tcl_UtfNext() calls will make the same steps as repeated Tcl_UtfToUniChar() calls again for valid UTF-8 sequences and (invalid, in case of TCL_UTF_MAX=3) 4-byte UTF-8 sequences.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  16. Ticket change [5e3475f277] (rid 182309) by jan.nijtmans on 2020-04-23 11:37:40:

    1. login: "jan.nijtmans"
    2. mimetype: "text/plain"
    3. resolution changed to: "Fixed"
    4. status changed to: "Pending"
  17. Ticket change [e3edf518bf] (rid 200228) by jan.nijtmans on 2022-04-18 17:22:06:

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