Skip to content
Tcl Source Code Artifact [3ab3ed9a7e]
Login

Artifact [3ab3ed9a7e]

Artifact 3ab3ed9a7efd2f2408c70780107e65d580467587319ef1f635913ed51dcf829e:

Ticket change [3ab3ed9a7e] - New ticket [b3628609ad73a105|b3628609ad] <i>concatening strings is broken when the &quot;bytes&quot; field of a Tcl_Obj contains invalid data and the type is not tclStringType</i>. by pooryorick on 2023-04-21 21:25:11.
D 2023-04-21T21:25:11.890
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment When\sthe\sfollowing\sscript\sis\sevaluated\sby\strunk\sbuild\sof\stcltest,\r\n<code>p1</code>\sproduces\sthe\sexpected\svalue,\s<code>2</code>,\swhereas\r\n<code>p2</code>\sproduces\san\sincorrect\svalue,\s<code>1</code>.\r\n\r\n\r\n<blockquote><code><verbatim>\r\nproc\sp1\s{}\s{\r\n\tstring\slength\s[testbytestring\s\\xc0][testbytestring\s\\x80]\r\n}\r\nproc\sp2\s{}\s{\r\n\tstring\slength\s[list\s[testbytestring\s\\xc0]][testbytestring\s\\x80]\r\n}\r\n\r\nputs\s[p1]\r\nputs\s[p2]\r\n</verbatim></code></blockquote>\r\n\r\n\r\nFor\s<code>p1</code>,\s<code>TclStringCat()</code>\suses\sthe\r\n<code>tclStringType</code>\sinternal\srepresentation\swhere\s<code>\\xc0</code>\sis\r\ntreated\sas\sa\ssingle\scharacter\sand\sso\sis\s<code>\\x80</code>,\sand\stherefore\r\ncharacter\sconcatenation\sis\sperformed\sproducing\sthe\scorrect\sresult.\r\n\r\nFor\s<code>p2</code>,\s<code>tclStringCat</code>\sdoes\snot\suse\r\n<code>tclStringType</code>\sbecause\sit\sdetects\sthat\sthere\sis\sanother\sinternal\r\nrepresentation\salready\sin\splace.\s\sInstead,\sit\ssimply\sconcatenates\sthe\s"bytes"\r\nfields\sof\sthe\svalues,\sand\stherefore\sbyte\sconcatenation\sis\sperformed,\sso\sthe\stwo\r\ninvalid\sbyte\ssequences\sbecome\sa\ssingle\svalid\sbyte\ssequence\sencoding\sone\r\ncharacter.\s\r\n\r\nIf\sthe\sbody\sof\s<code>p2</code>\sis\sevaluated\sdirectly\sinstead\sof\sin\sthe\sbody\sof\r\na\sprocedure,\sthe\sresult\sis\s<code>2</code>\sinstead\sof\s<code>1</code>.\s\sThis\r\nhappens\sbecause\sthere\sis\sno\sbytecode\sto\sexecute,\sand\sinstead\r\n<code>TclEvalEx</code>\scalls\s<code>TclSubstTokens()</code>,\swhich\sdoes\snot\scall\r\n<code>TclStringCat</code>,\sbut\sinstead\scalls\s<code>Tcl_AppendObjToObj</code>,\r\nwhich\sreplaces\sthe\slist\sinternal\srepresentation\swith\sa\r\n<code>tclSringType</code>\sinternal\srepresentation,\sand\seventually\scalls\r\n<code>AppendUtfToUnicodeRep()</code>.
J is_private 0
J login pooryorick
J priority 5\sMedium
J private_contact 2b2275eab1118e1fab0016cf1c5702893c6af86c
J resolution None
J severity Minor
J status Open
J submitter pooryorick
J subsystem -\sNew\sBuiltin\sCommands
J title concatening\sstrings\sis\sbroken\swhen\sthe\s"bytes"\sfield\sof\sa\sTcl_Obj\scontains\sinvalid\sdata\sand\sthe\stype\sis\snot\stclStringType
J type Bug
K b3628609ad73a105f0e51435e0e0ac5b8205fad7
U pooryorick
Z 48e84ff45e43b2851ffdb1fe2f0f09b2