Skip to content
Tcl Source Code Artifact [5385a97373]
Login

Artifact [5385a97373]

Artifact 5385a97373207ed9daf4bb9bcf283cdb8604418b444e3dda1995b1badc7e5bc1:

Ticket change [5385a97373] - Ticket [b3628609ad73a105|b3628609ad] <i>concatenating strings is broken when the &quot;bytes&quot; field of a Tcl_Obj contains invalid data and the type is not tclStringType</i> status still Open with 3 other changes by pooryorick on 2023-05-02 15:25:23.
D 2023-05-02T15:25:23.486
J icomment I\sagree\sthat\sTcl\sshould\sbe\sable\sto\sretain\sefficient\sfunctions\ssuch\sas\r\n<code>TclStringCat()</code>.\s\sI\sthink\sthat\sin\sthis\scase\sit\sis\sthe\stest\sthat\sis\r\nwrong,\snot\s<code>TclStringCat()</code>.\s\sTcl\snever\sstores\simproperly-encoded\r\ndata\sin\s<code>Tcl_Obj.bytes</code>,\swhich\sis\sdocumented\sto\scontain\sdata\r\nencoded\sin\sutf-8,\swith\seach\snul\scharacter\sbeing\srepresented\sin\sits\soverlong\r\nutf-8\sform,\s<code>\\xC0\\x80</code>.\s\sThus,\sa\sfunction\slike\r\n<code>TclStringCat()</code>\sshould\sbe\sable\sto\sassume\sthat\sin\sthe\scatenation\sof\r\n<code>Tcl_Obj.bytes</code>\svalues\sthere\sis\sno\schange\sto\sthe\sinterepretation\sof\r\nany\sbyte\sin\sany\sof\sthe\scatenated\svalues.\r\n\r\n<code>TclStringCat</code>\swas\scompetently\swritten\swith\sthat\sin\smind\sto\sachieve\r\nthe\sfollowing\sgoals:\r\n\r\n\s\s\s\s*\s\sAvoid\sshimmering\s&\sstring\srep\sgeneration.\r\n\s\s\s\s*\s\sProduce\spure\sbytearray\swhen\spossible.\r\n\s\s\s\s*\s\sError\son\soverflow.\r\n\r\nIn\s2021\sthe\scommits\s[fd66e6e20e]\sand\s[a7df881994]\smodified\r\n<code>TclStringCat()</code>\sto\sforce\sthe\sgeneration\sof\sa\r\n<code>tclStringType</code>\sinternal\srepresentation\sin\sorder\sto\savoid\sthe\seffect\r\nof\scombining\stwo\sotherwise\sunrelated\sincomplete\sbyte\ssequences\sinto\sone\r\ncomplete\ssequence.\s\sThis\schange\sdegraded\s<code>TclStringCat()</code>\swith\r\nrespect\sto\sits\sstated\sgoals.\s\sThe\scurrent\sissue\sreport\scould\sprobably\sbe\r\nresolved\sby\sfurther\sdegrading\s<code>TclStringCat()</code>\sin\sa\ssimilar\sway,\sbut\r\nthat\swould\smove\sTcl\sfurther\sin\sthe\swrong\sdirection\sof\ssupporting\sincomplete\r\nvalues\sin\s<code>Tcl_Obj.bytes</code>.\r\n\r\nAs\sI\sstated\sa\scouple\sof\syears\sago\sin\s[7f1162a867],\sany\sthird\sparty\sthat\sstores\r\nimproperly-encoded\sdata\sin\s<code>Tcl_Obj.bytes</code>\sis\screating\sa\r\ngarbage-in/garbage-out\ssituation,\sand\sshould\snot\sexpect\sthe\sresults\sof\sany\sTcl\r\nfunctions\sthereafter\sto\smake\ssense.\s\sThird\sparties\smust\suse\r\n<code>Tcl_ExternalTo*</code>\sfunctions\sto\sproduce\sproperly-encoded\svalues.\s\sIf\r\na\sthird\sparty\sdirectly\smodifies\s<code>Tcl_Obj.bytes</code>\ssuch\sthat\sthe\slast\r\nbyte\ssequence\sfor\san\sencoded\scode\spoint\sisn't\scomplete,\sthen\sit\sshould\snot\r\nexpect\sTcl\sto\sinterpret\sthat\ssequence\sas\scomplete.\r\n\r\nEither\sthird\sparties\spay\sa\srelatively\ssmall\spenalty\sof\sproperly-encoding\svalues\r\nat\sthe\sboundary\sof\sTcl,\sor\sTcl\spays\sa\srelatively\slarge\spenalty\sthroughout\sits\r\ninternal\sroutines,\sand\sat\sa\scost\sof\sgreater\scode\scomplexity.\r\n\r\nFixed\sin\s[2ddc0c3fa9]\sby\sallowing\s<code>TclStringCat()</code>\sto\sassume\sthat\r\nall\s<code>Tcl_Obj.bytes</code>\svalues\scan\sbe\ssafely\scatenated\sas-is.
J login pooryorick
J mimetype text/x-fossil-wiki
K b3628609ad73a105f0e51435e0e0ac5b8205fad7
U pooryorick
Z 3d70048174280e082773798e46b2e0a6