Artifacts Associated With Ticket c9f0520f7e
Ticket change [3e0f6aaaad] (rid 242356) by elio_du on 2025-07-09 15:45:39:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-plain"
- 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 ------------------------------------------- - foundin initialized to: "8.6.11"
- is_private initialized to: "0"
- login: "elio_du"
- priority initialized to: "5 Medium"
- private_contact initialized to: "36ae4f4121e0beea41dc8655c6d0658cff1db08d"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "elio_du"
- subsystem initialized to: "11. Conversions from String"
- title initialized to:
ckalloc argument overflow in Tcl_SplitList with a string about 1
- type initialized to: "Bug"
Ticket change [3afb4f0bee] (rid 242774) by apnadkarni on 2025-07-15 03:32:58:
- icomment:
Proposed fix is in [7fd8657f04]. Note Tcl_SplitList will return an error, not panic, so caller needs to check return status.
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [6a860c4b9b] (rid 243035) by apnadkarni on 2025-07-16 12:03:12:
- 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 ``` - login: "apnadkarni"
- mimetype: "text/plain"
- icomment:
Ticket change [76695072ea] (rid 243043) by apnadkarni on 2025-07-16 16:36:23:
- closedate changed to: "2460873.19194314"
- closer changed to: "apnadkarni"
- icomment: "Fixed in [1eebbe69f5]."
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"