Skip to content
Tcl Source Code History Of Ticket b79df322a9
Login

History Of Ticket b79df322a9

Artifacts Associated With Ticket b79df322a9

  1. Ticket change [0ce01f1766] (rid 202221) by apnadkarni on 2022-06-29 14:01:55:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      The Tcl_NewUnicodeObj function truncates passed in strings to half their length.
      
      Culprit is a memcpy of nchars instead of of nchars*sizeof(unsigned short).
      
      However, it is not clear to me that this is the only issue in that module.
      The new String internal rep hosts the string in the unicode[] array, typed
      as Tcl_UniChar. The Tcl_NewUnicodeObj on the other hand manipulates data as
      unsigned short, not Tcl_UniChar. I assume this is because Tcl_NewUnicodeObj
      is intended to deal with UTF-16 in all cases, even when Tcl_UniChar is 4 bytes
      (TCL_UTF_MAX==4). If that is the case, then the line
      
      stringPtr->unicode[numChars] = 0;
      
      will overwrite memory since the allocation is done assuming 2-byte units and 
      sizeof(unicode[0]) is 4 bytes. On the other hand, if Tcl_UniChar is always 2 
      bytes then why is the function defined using unsigned shorts.
      
      I have similar doubts about other usage in the module. For example in 
      SetUTF16StringFromAny (around line 215), the code is allocating in unsigned 
      short units but terminating as an array of Tcl_UniChar.
      
      So also Tcl_SetUnicodeObj. May be others, I did not check the whole module.
      
      I have not provided a patch because I'm not sure if my analysis is correct
      (other than the memcpy fix). Can the String.unicode[] array contain either 
      2-byte or 4-byte units? If so distinguishing using a union may be clearer.
      
    5. foundin initialized to: "8.7"
    6. is_private initialized to: "0"
    7. login: "apnadkarni"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "apnadkarni"
    13. subsystem initialized to: "- New Builtin Object Types"
    14. title initialized to: "Tcl_NewUnicodeObj truncates strings"
    15. type initialized to: "Bug"
  2. Ticket change [cc12a24c71] (rid 202222) by apnadkarni on 2022-06-29 14:03:17:

    1. icomment:
      As an aside, I was surprised the test suite does not catch such an obvious bug. Grepping the code, looks like the function is never used internally.
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  3. Ticket change [f4c7f39285] (rid 202223) by apnadkarni on 2022-06-29 14:04:28:

    1. login: "apnadkarni"
    2. mimetype: "text/plain"
    3. priority changed to: "9 Immediate"
    4. severity changed to: "Critical"
  4. Ticket change [f5f8b1c874] (rid 202227) by jan.nijtmans on 2022-06-30 11:35:04:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459760.98268856"
    3. closer changed to: "jan.nijtmans"
    4. icomment:
      Thanks for catching this bug. Indeed, the new Tcl_NewUnicodeObj() is not used internally any more, that made it possible for this bug to slip through. It came in through TIP #622, which is - apparently - not tested enough yet.
      
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
  5. Ticket change [d8fd460018] (rid 202228) by apnadkarni on 2022-06-30 12:08:11:

    1. closer changed to: "nobody"
    2. icomment:
      Jan,
      
      Re-opening because the second part of my ticket was not addressed. Is the line 
      
      stringPtr->unicode[numChars] = 0;
      
      not a problem when Tcl_UniChar maps to an int? If not, why not?
      
      /Ashok
      
    3. login: "apnadkarni"
    4. mimetype: "text/plain"
    5. status changed to: "Open"
  6. Ticket change [bded36d755] (rid 202229) by jan.nijtmans on 2022-06-30 12:58:45:

    1. icomment:
      See: [https://core.tcl-lang.org/tcl/file?udc=1&ln=57-59&ci=936c4f4b1c02835d&name=generic%2FtclStringRep.h|tclStringRep.h].
      
      Answer: 'unicode' here is an array of 'unsigned short', not an array of Tcl_UniChar's
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
    4. status changed to: "Pending"
  7. Ticket change [9eb1d9bd28] (rid 202230) by apnadkarni on 2022-06-30 13:04:55:

    1. icomment:
      Oops. Mea culpa. I was looking at the UniCharString structure in tclStringObj.c which has it as array of Tcl_UniChar
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  8. Ticket change [8973d8fd3c] (rid 202231) by apnadkarni on 2022-06-30 13:05:12:

    1. closedate changed to: "2459761.04528348"
    2. closer changed to: "apnadkarni"
    3. login: "apnadkarni"
    4. mimetype: "text/plain"
    5. status changed to: "Closed"
  9. Ticket change [9b1ec5a041] (rid 202519) by apnadkarni on 2022-07-12 10:37:22:

    1. closedate changed to: "2459772.94261816"
    2. icomment:
      I added testunicodestring command to the test suite to ensure Tcl_*Unicode* is tested as Tcl itself does not use it.
      
      Re-opening for the record because I now get a crash.
      
      Investigating...
      
    3. login: "apnadkarni"
    4. mimetype: "text/plain"
  10. Ticket change [926cf93eb8] (rid 202520) by apnadkarni on 2022-07-12 11:20:56:

    1. closedate changed to: "2459772.97287345"
    2. icomment:
      Ok, there are multiple issues. 
      
      First, `Tcl_GetUnicodeFromObj` is missing a `numChars < 0` test.
      
      Second, I take back my mea culpa. I was right earlier. `TclGetUnicodeFromObj` (which takes `unsigned short` strings) calls `SetStringFromAny` which converts the object's internal representation to a `UniCharString`, not a String which is what `TclGetUnicodeFromObj` expects with obviously errnoneous results.
      
      Fixing and adding tests.
      
    3. login: "apnadkarni"
    4. mimetype: "text/x-markdown"
  11. Ticket change [2f7d97db77] (rid 202521) by apnadkarni on 2022-07-12 11:21:28:

    1. closer changed to: "nobody"
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
    4. resolution changed to: "Accepted"
    5. status changed to: "Open"
  12. Ticket change [ac6bf210a9] (rid 202522) by jan.nijtmans on 2022-07-12 11:50:52:

    1. icomment:
      Indeed, this should have been:
      <pre>
      Index: generic/tclStringObj.c
      ==================================================================
      --- generic/tclStringObj.c
      +++ generic/tclStringObj.c
      @@ -982,11 +982,11 @@
                                       * rep's unichar length should be stored. If
                                       * NULL, no length is stored. */
       {
           String *stringPtr;
      
      -    SetStringFromAny(NULL, objPtr);
      +    SetUTF16StringFromAny(NULL, objPtr);
           stringPtr = GET_STRING(objPtr);
      
           if (lengthPtr != NULL) {
              *lengthPtr = stringPtr->numChars;
           }
      
      
      </pre>
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  13. Ticket change [bd4d6ef1c0] (rid 202526) by jan.nijtmans on 2022-07-12 12:25:19:

    1. icomment:
      It should even be, slighty more complicated: [0e4cbe7bef99f2a7]
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  14. Ticket change [2140d1b594] (rid 202578) by jan.nijtmans on 2022-07-13 14:45:19:

    1. closedate changed to: "2459774.11480677"
    2. closer changed to: "jan.nijtmans"
    3. icomment: "Should be fixed [6c065977dc05df50|here]"
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
  15. Ticket change [b745e036be] (rid 202608) by jan.nijtmans on 2022-07-14 11:58:35:

    1. closedate changed to: "2459774.99901677"
    2. icomment:
      Same bugfix: [f3a9189fb47b2491], but now for Tcl_AppendUnicodeToObj() too.
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"