Skip to content
Tcl Source Code Artifact [0ce01f1766]
Login

Artifact [0ce01f1766]

Artifact 0ce01f176698410b83e185fca69f3ed78f46227b75548990f3fc11bbe4dbb853:

Ticket change [0ce01f1766] - New ticket [b79df322a927dee6|b79df322a9] <i>Tcl_NewUnicodeObj truncates strings</i>. by apnadkarni on 2022-06-29 14:01:55.
D 2022-06-29T14:01:55.602
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment The\sTcl_NewUnicodeObj\sfunction\struncates\spassed\sin\sstrings\sto\shalf\stheir\slength.\r\n\r\nCulprit\sis\sa\smemcpy\sof\snchars\sinstead\sof\sof\snchars*sizeof(unsigned\sshort).\r\n\r\nHowever,\sit\sis\snot\sclear\sto\sme\sthat\sthis\sis\sthe\sonly\sissue\sin\sthat\smodule.\r\nThe\snew\sString\sinternal\srep\shosts\sthe\sstring\sin\sthe\sunicode[]\sarray,\styped\r\nas\sTcl_UniChar.\sThe\sTcl_NewUnicodeObj\son\sthe\sother\shand\smanipulates\sdata\sas\r\nunsigned\sshort,\snot\sTcl_UniChar.\sI\sassume\sthis\sis\sbecause\sTcl_NewUnicodeObj\r\nis\sintended\sto\sdeal\swith\sUTF-16\sin\sall\scases,\seven\swhen\sTcl_UniChar\sis\s4\sbytes\r\n(TCL_UTF_MAX==4).\sIf\sthat\sis\sthe\scase,\sthen\sthe\sline\r\n\r\nstringPtr->unicode[numChars]\s=\s0;\r\n\r\nwill\soverwrite\smemory\ssince\sthe\sallocation\sis\sdone\sassuming\s2-byte\sunits\sand\s\r\nsizeof(unicode[0])\sis\s4\sbytes.\sOn\sthe\sother\shand,\sif\sTcl_UniChar\sis\salways\s2\s\r\nbytes\sthen\swhy\sis\sthe\sfunction\sdefined\susing\sunsigned\sshorts.\r\n\r\nI\shave\ssimilar\sdoubts\sabout\sother\susage\sin\sthe\smodule.\sFor\sexample\sin\s\r\nSetUTF16StringFromAny\s(around\sline\s215),\sthe\scode\sis\sallocating\sin\sunsigned\s\r\nshort\sunits\sbut\sterminating\sas\san\sarray\sof\sTcl_UniChar.\r\n\r\nSo\salso\sTcl_SetUnicodeObj.\sMay\sbe\sothers,\sI\sdid\snot\scheck\sthe\swhole\smodule.\r\n\r\nI\shave\snot\sprovided\sa\spatch\sbecause\sI'm\snot\ssure\sif\smy\sanalysis\sis\scorrect\r\n(other\sthan\sthe\smemcpy\sfix).\sCan\sthe\sString.unicode[]\sarray\scontain\seither\s\r\n2-byte\sor\s4-byte\sunits?\sIf\sso\sdistinguishing\susing\sa\sunion\smay\sbe\sclearer.
J foundin 8.7
J is_private 0
J login apnadkarni
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter apnadkarni
J subsystem -\sNew\sBuiltin\sObject\sTypes
J title Tcl_NewUnicodeObj\struncates\sstrings
J type Bug
K b79df322a927dee6517ed87b918b02117d4a8d2e
U apnadkarni
Z 25ae14fc8c06f8b4b40e231f77822f42