.
D 2020-04-27T19:05:44.950
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment When\siterating\sthrough\sa\scounted\s(not\sNUL-terminated)\sUTF-8\sstring\svia\scalls\sto\r\nTcl_UtfToUniChar(),\san\simportant\sissue\sis\show\sto\skeep\soperations\sfrom\srunning\r\npast\sthe\smemory\sapproved\sfor\suse.\s\sFailure\sto\sdo\sthis\smight\sinvolve\stransgressing\r\nmemory\sboundaries,\sor\sit\smight\sinvolve\sreading\sand\sacting\son\suninitialized\sbits\r\nfound\sin\smemory\sthe\scaller\swas\snever\sgiven\spermission\sto\sread.\r\n\r\nThe\salgorithm\sembedded\sin\sseveral\splaces\sin\sTcl\sis\sto\smake\suse\sof\r\nTcl_UtfCharComplete()\sto\scheck\swhether\sa\scall\sto\sTcl_UtfToUniChar()\sis\r\nsafe\sto\smake\swith\sa\sgiven\snumber\sof\sbytes\sleft\sin\sthe\sstring.\s\sOne\skey\r\ninvariant\sthat\sthese\salgorithms\srely\son\sis\sthat\sTcl_UtfCharComplete(p,\sn)\r\nwill\sreturn\strue\swhenever\sn\s>=\sTCL_UTF_MAX.\s\sCallers\smake\suse\sof\sthis\r\ninvariant.\s\sThey\sskip\smaking\sthe\sTcl_UtfCharComplete()\scall\sthat\sthey\r\nalready\sknow\swill\sreturn\strue,\sand\ssave\sthose\scalls\sonly\sfor\sthe\stail\send\r\nof\sthe\sstring\swhen\sthere\sare\s(TCL_UTF_MAX\s-\s1)\sor\sfewer\sbytes\sleft.\r\n\r\nThe\sconsequence\sis\sthat\sTcl_UtfToUniChar()\sshould\snever\sread\smore\sthan\r\nTCL_UTF_MAX\sbytes.\s\sStarting\sin\sTcl\s8.6.10\sit\sis\sdoing\sso.\s\sWhen\sp\spoints\sto\r\na\sbyte\sin\sthe\srange\s0xF0\s-\s0xF7,\sthe\smemory\sp[3]\sis\sread.\sThis\seliminates\r\nthe\scoding\sguarantee\sthat\sthese\siteration\stasks\sare\srelying\son.\r\n\r\nThese\salgorithms\sare\sin\sTcl\sitself.\s\sThere\swas\sone\sin\sTcl_NumUtfChars,\swhich\r\nled\sto\sthe\sfailure\sof\stest\sutf-4.11\s(new\ssince\sthe\s8.6.10\srelease).\s\sThe\r\nTcl_NumUtfChars\sroutine\shas\sbeen\srevised\son\sthe\score-8-6-branch\stip\sto\swork\r\naround\sthis\sbroken\scontract,\sbut\sthat's\snot\sa\sreasonable\sanswer\sthat\scan\sbe\sgiven\r\nto\sextensions\sbroken\sby\sa\spatch\srelease\schange\sin\sa\spublic\sroutine.\r\n\r\nThese\salgorithms\sare\salso\sin\sthe\sencoding\smachinery\sof\schannels.\s\sIt\sshould\r\nnot\sbe\sdifficult\sto\scook\sup\sa\sdemonstration\scase\swhere\sthis\schange\swill\r\ncorrupt\sthe\sbuffer\smanagement\sthere,\sor\sat\sleast\sa\sscenario\swhere\smem\sdebug\r\nor\svalgrind\sruns\sof\sTcl\swill\sreport\stroubles.\r\n\r\nI'm\snot\slooking\sfor\sa\squick\sfix\shere.\s\sI\sknow\sthis\sis\sa\sdifficult\sissue\senmeshed\r\nin\swork\stoward\svery\simportant\snew\sfunctionality,\sand\stoward\smaking\sTcl\sbegin\r\nto\soffer\scorrectness\sin\sstring\sprocessing\sthat\shas\sbeen\smissing\sa\slong\stime.\r\nI'll\skeep\smy\sefforts\sat\sa\sresolution\sin\sa\sfeature\sbranch\suntil\sthey\scan\sget\sreview.
J foundin 8.6.10
J is_private 0
J login dgp
J priority 5\sMedium
J resolution None
J severity Important
J status Open
J submitter dgp
J subsystem 44.\sUTF-8\sStrings
J title Tcl_UtfToUniChar\sreads\smore\sthan\sTCL_UTF_MAX\sbytes
J type Bug
K ed29806bafd93096f71fb55248258138125805a6
U dgp
Z a986324f157ada2421e29195af0f3943