Skip to content
Tcl Source Code History Of Ticket c9f0520f7e
Login

History Of Ticket c9f0520f7e

Artifacts Associated With Ticket c9f0520f7e

  1. Ticket change [3e0f6aaaad] (rid 242356) by elio_du on 2025-07-09 15:45:39:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-plain"
    4. comment initialized to:
      The ckalloc tries to allocate size * sizeof(char*) + length + 1, if since sizeof(char*) in 64bit machine is 8 bytes, for the extreme case string is "0 1 2 3 4 5 ...", size can be so size is half size of string itself, so it takes much smaller string to cause size * sizeof(char*) + length + 1 to hit the 2^32 limit.
      
      This issue is not presenting in Tcl 9 as datatype is now 64bit, still would rather Tcl_panic with some error message instead of SEGV directly.
      
      To reproduce:
      ---------------------------------------------
      
      static int Crash_Cmd(ClientData cdata, Tcl_Interp *interp, int objc,
                           Tcl_Obj *const objv[]) {
        if (objc < 2) {
          return TCL_ERROR;
        }
        const char * str = Tcl_GetString(objv[1]);
        char **list_elements = NULL;
      
      #if TCL_MAJOR_VERSION == 9
        long int list_sz = 0;
        (void)Tcl_SplitList(interp, str, &list_sz, (CONST86 char ***)&list_elements);
      #else
        int list_sz = 0;
        (void)Tcl_SplitList(interp, str, &list_sz, (CONST84 char ***)&list_elements);
      #endif
      
        printf("SPLITTED INTO %d elements\n", list_sz);
      
        for (long int i = 0; i < list_sz; i ++) {
          if (i % 1024 == 0) {
            printf("%ld:%s\n", i, list_elements[i]);
          }
        }
      
        Tcl_SetObjResult(interp, Tcl_NewStringObj("Crash", -1));
        return TCL_OK;
      }
      
      /*
        * Crash_Init -- Called when Tcl loads your extension.
        */
       int DLLEXPORT
       Crash_Init(Tcl_Interp *interp)
       {
         if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
           return TCL_ERROR;
         }
         /* changed this to check for an error - GPS */
         if (Tcl_PkgProvide(interp, "Crash", "1.0") == TCL_ERROR) {
           return TCL_ERROR;
         }
         Tcl_CreateObjCommand(interp, "crash", Crash_Cmd, NULL, NULL);
         return TCL_OK;
       }
      -----------------------------------------
      
      Test.tcl:
      ----------------------------------------
      load ./libcrash.so
      
      # create a huge string
      # crash by 26 in 8.6.11
      set limit 26
      set str "0 1 2 3 4 5 6 7 8 9 "
      for { set i 0 } { $i < $limit } { incr i } {
        set str "$str $str"
        puts "doubled $i: [expr [string length $str] / 1024.0 / 1024] MB"
      }
      
      crash "$str"
      exit
      -------------------------------------------
      
    5. foundin initialized to: "8.6.11"
    6. is_private initialized to: "0"
    7. login: "elio_du"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "36ae4f4121e0beea41dc8655c6d0658cff1db08d"
    10. resolution initialized to: "None"
    11. severity initialized to: "Critical"
    12. status initialized to: "Open"
    13. submitter initialized to: "elio_du"
    14. subsystem initialized to: "11. Conversions from String"
    15. title initialized to:
      ckalloc argument overflow in Tcl_SplitList with a string about 1
      
    16. type initialized to: "Bug"
  2. Ticket change [3afb4f0bee] (rid 242774) by apnadkarni on 2025-07-15 03:32:58:

    1. icomment:
      Proposed fix is in [7fd8657f04]. Note Tcl_SplitList will return an error, not panic, so caller needs to check return status.
      
    2. login: "apnadkarni"
    3. mimetype: "text/x-fossil-plain"
  3. Ticket change [6a860c4b9b] (rid 243035) by apnadkarni on 2025-07-16 12:03:12:

    1. icomment:
      Thanks for the report and analysis. To reproduce without an extension,
      
      ```
      # create a huge string
      # crash by 26 in 8.6.11
      set limit 26
      set str "0 1 2 3 4 5 6 7 8 9 "
      for { set i 0 } { $i < $limit } { incr i } {
          set str "$str $str"
          puts [string length $str]
      }
      
      proc p {} [list dict for $str {} {}]
      p
      ```
      
    2. login: "apnadkarni"
    3. mimetype: "text/plain"
  4. Ticket change [76695072ea] (rid 243043) by apnadkarni on 2025-07-16 16:36:23:

    1. closedate changed to: "2460873.19194314"
    2. closer changed to: "apnadkarni"
    3. icomment: "Fixed in [1eebbe69f5]."
    4. login: "apnadkarni"
    5. mimetype: "text/x-fossil-plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"