<i>Crash on invalid Unicode code points</i> status still Open with 3 other changes
by
.
D 2026-11-25T11:24:43.558
J icomment The\scrash\swas\scaused\sby\sa\smismatch\sbetween\s`TclUtfCount`\sand\s`Tcl_UniCharToUtf`.\sThe\sformer\sreturned\s2\sfor\sthe\snumber\sof\sbytes\sneeded\sto\sencode\sthe\svalue\sbecause\sof\sa\sbroken\ssigned\scompare,\swhile\sthe\slatter\smapped\sthe\sinvalid\svalue\sto\s0xFFFD\swhich\sis\sencoded\sas\s3\sbytes.\sThe\s`ExtendRepWithUnicode`\sused\sthe\sformer\sto\sdetermine\sbuffer\ssize\sand\sthe\slatter\sto\sdo\sthe\sactual\sencoding\swith\sobvious\sconsequences.\sProposed\sfix\sin\sthe\sbug-28de50dcee\sbranch.\r\n\r\nReviewing\sthe\scode\salso\srevealed\sanother\sdiscrepancy.\r\n\r\n`TclUtfCount(0x01000061)`\sreturns\s3,\spresumably\sexpecting\san\sencoding\sof\s0xFFFD,\swhile\s`Tcl_UniCharToUtf`\sencodes\sit\sas\sa\ssingle\sbyte.\sThe\seffect\sof\sthis\sinconsistency\swill\snot\sbe\sas\sdrastic\sas\sthe\scrash\sabove\sbut\scan\sstill\shave\sunintended\seffects.\sMoreover\sthe\sbehavior\sof\s`Tcl_UniCharToUtf`\sis\ssimply\swrong.\sIt\smaps\sthe\sillegal\scode\spoint\sto\san\sinternal\sTUTF-8\srepresentation\sof\sthe\svalid\scharacter\s'a'.\r\n\r\n```\r\n%\steststringobj\snewunicode\s0\s\s0x01000061\r\na\r\n```\r\n\r\nIt\sis\scaused\sby\sthe\sbit\s0x01000000\sbeing\streated\sas\sthe\sTCL_COMBINE\sflag\swhich\sis\smasked\soff\sby\s`Tcl_UniCharToUtf`\sresulting\sin\sthe\sseen\sbehaviour.\sThis\sis\ssimply\swrong\sin\smy\sview.\sAs\sfar\sas\sI\scan\stell,\sthere\sis\sno\sneed\sin\sTcl\s9\sfor\sthis\sflag\sand\sit\sshould\sbe\sremoved.\sPassing\sa\sprogramming\sflag\sas\spart\sof\sthe\sdatum\sitself\sis\snever\sa\sgood\sidea.\r\n\r\nWhile\sthese\sissues\sdeal\swith\sinvalid\sdata,\sthey\sstill\sshould\snot\scause\scrashes\sor\sill\sbehaviour\sand\sTcl\sshould\sdeal\swith\sthem\sas\sconsistently\sas\spossible.
J login apnadkarni
J mimetype text/x-markdown
K 28de50dcee4f6888eaed987bf1d795ac67138b5f
U apnadkarni
Z 48a4e1f4a30bebb2851118c3a898ea9e