Artifacts Associated With Ticket f04e9b1304
Ticket change [72eaf52288] (rid 254584) by serhiy.storchaka on 2026-06-25 07:41:28:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
## Problem `Tcl_UtfToUpper/Lower/Title()` overrun their in-place buffer and crash on a **genuine 4-byte UTF-8** non-BMP character (not Tcl's internal surrogate-pair form): ```c char buf[64] = "\xF4\x8F\xBF\xBF"; /* U+10FFFF */ Tcl_UtfToTitle(buf); /* SIGSEGV */ ``` No pure-Tcl reproducer exists — script ingestion decodes to the surrogate-pair form first, which is safe. It only bites an embedder that passes canonical UTF-8 to the C API. Tk does exactly that when it title-cases a class name during init, which is how CPython crashes: `tkinter.Tk(className='\U0010FFFF')` (gh-126219). ## Cause `generic/tclUtf.c`. The guard meant to prevent in-place growth is ```c if (len < UtfCount(Char)) memmove(dst, src, len); /* keep original */ else dst += TclUCS4ToUtf(Char, dst); /* write converted */ ``` For a 4-byte input, `len == 4` but `UtfCount()` returns **3** for a non-BMP character (its `return 4` is under `#if TCL_UTF_MAX > 3`), while `TclUCS4ToUtf()` actually writes **6** bytes (a surrogate pair). So `4 < 3` is false, 6 bytes are written over the 4-byte slot, `dst` overtakes `src`, the NUL is clobbered, and the loop runs off the buffer. ## Fix Make `UtfCount()` return the true size in a `TCL_UTF_MAX=3` build: ```c #if TCL_UTF_MAX > 3 if (((unsigned)(ch - 0x10000) <= 0xFFFFF)) { return 4; } #else if (((unsigned)(ch - 0x10000) <= 0xFFFFF)) { /* A non-BMP character is stored as a 2 x 3-byte surrogate pair. */ return 6; } #endif return 3; ``` Now `4 < 6` is true: the genuine-4-byte character is passed through unchanged (in-place conversion can't grow it safely), while the surrogate-pair form (`len == 6`) still converts. No change for `TCL_UTF_MAX > 3`. - foundin initialized to: "8.6 (`TCL_UTF_MAX=3`, the default)"
- is_private initialized to: "0"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- private_contact initialized to: "c62cfa96d21fcf0294bdb27e141b4604475a3f46"
- resolution initialized to: "None"
- severity initialized to: "Important"
- status initialized to: "Open"
- submitter initialized to: "serhiy.storchaka"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
Crash in Tcl_UtfToUpper/Lower/Title on a genuine 4-byte UTF-8 character
- type initialized to: "Bug"
Add attachment "tcl86-utfcount-nonbmp-crash.patch" [6159f57da2] (rid 254585) by serhiy.storchaka on 2026-06-25 07:42:55.
Ticket change [f1668d9b4b] (rid 254624) by oehhar on 2026-06-29 08:15:37:
- icomment:
This is 8.6 which is end of life. Someone may nevertheless apply the patch. Give a sign if you want commit rights to do it on your own. Thanks for all, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [476081d4ed] (rid 254625) by dgp on 2026-06-29 14:06:41:
- icomment:
I'm not convinced over commit rights for purpose of continuing development of Tcl 8. I don't think fossil has per-branch permissions. Isn't it a better idea for folks who want to adopt Tcl 8 to make their own fork repository?
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [092616596c] (rid 254626) by oehhar on 2026-06-30 07:31:20:
- icomment:
I tihnk, it is a good idea to merge patches to core-8-6-branch. It might be helpful for someone... Sergey still puts patches in 8.5... And the alternative is a github fork what I want to avoid. Serhiy comes from tkinter and reported, that a lot is still on 8.6, as 9.0 migration just started in new linux distributions. I find it a good think if we get tkinter people in. They have different interest and don't know fossil, so any help is appreciated. Thanks for all, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [967f9938ba] (rid 254647) by jan.nijtmans on 2026-06-30 12:30:35:
- icomment:
> I tihnk, it is a good idea to merge patches to core-8-6-branch I have no problem doing that, for trivial fixes like this one.
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [02667bc0c7] (rid 254648) by jan.nijtmans on 2026-06-30 12:33:01:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461222.0229352429"
- closer changed to: "jan.nijtmans"
- icomment:
Fixed [8fdf2f999ce788ba|here] Will (most likely) never land in an official release
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"