Skip to content
Tcl Source Code Artifact [85a32ab58a]
Login

Artifact [85a32ab58a]

Artifact 85a32ab58a46814bae4402301aedffad9006491c7595853c410aeb67e6abeddb:

Ticket change [85a32ab58a] - New ticket [1bd796d9c2915891|1bd796d9c2] <i>multiple issues in Tcl_DString functions</i>. by chrstphrchvz on 2022-04-11 21:27:55.
D 2022-04-11T21:27:55.432
J assignee nobody
J closer nobody
J cmimetype text/x-fossil-wiki
J comment There\sare\smultiple\sinstances\sof\ssigned\sinteger\soverflow\sin\s<tt>Tcl_DString</tt>\sfunctions.\sBut\sI\sam\snot\smerely\sproposing\sthat\sthe\soverflowing\soperations\sbe\sperformed\sas\s<tt>unsigned\sint</tt>,\sbecause\sthere\swould\sstill\sbe\sproblematic\sbehavior,\ssuch\sas\san\sinfinite\sloop\sin\s<tt>Tcl_ExternalToUtfDString()</tt>\sduring\s<tt>encoding\sconvertfrom\s…</tt>\sin\sthis\sexample\s(assuming\sit\sdoesn’t\sfirst\spanic\sdue\sto\sinsufficient\smemory):\r\n\r\n<pre>\r\nset\sf\s&#91;open\s/dev/zero\s&#91;list\sRDONLY\sBINARY&#93;&#93;\r\nfconfigure\s$f\s-buffersize\s&#91;expr\s{2**20}&#93;\r\nputs\s&#91;time\s{set\sz\s&#91;read\s$f\s&#91;expr\s{2**30-1}&#93;&#93;}\s1&#93;\r\nputs\s&#91;::tcl::unsupported::representation\s$z&#93;\r\nputs\s&#91;time\s{set\sa\s&#91;string\scat\s&#91;encoding\sconvertto\sascii\s{a}&#93;\s$z&#93;}\s1&#93;\r\nputs\s&#91;::tcl::unsupported::representation\s$a&#93;\r\nputs\s&#91;time\s{set\ss\s&#91;encoding\sconvertfrom\sascii\s$a&#93;}\s1&#93;\r\nputs\s&#91;::tcl::unsupported::representation\s$s&#93;\r\n</pre>\r\n\r\nThe\sinfinite\sloop\sis\sdue\sto\snever\sbeing\sable\sto\sgrow\sthe\sdestination\sstring\slarge\senough\sfor\s<tt>TableToUtfProc()</tt>\sto\sstop\sreturning\s<tt>TCL_CONVERT_NOSPACE</tt>.\sThere\sis\salso\soverflow\swraparound\swhich\scauses\sthe\sdestination\sstring\sto\sbe\sunexpectedly\struncated,\slosing\spart\sof\sthe\sresult.\r\n\r\nIf\sthese\ssorts\sof\sissues\sare\sto\sbe\sresolved\s(rather\sthan\sconsidered\swon’t-fix\sfor\sTcl\s8),\sit\sseems\sthere\swould\sfirst\sneed\sto\sbe\sa\sdecision\smade\son\swhat\sthe\sintended\sbehaviors\sare;\sI’m\snot\ssure\sif\sI\scan\sidentify\sall\sof\sthem.\sBut\sthis\swould\sinclude\sdeciding\swhat\sthe\smaximum\sallowed\s<tt>length</tt>\sshould\sbe:\sit\sseems\spossible\sto\ssupport\s<tt>length\s==\sINT_MAX</tt>\sby\shaving\sTcl\sinternally\streat\s<tt>spaceAvl</tt>\sas\sif\sit\swere\s<tt>unsigned\sint</tt>\s(since\sclients\saren’t\ssupposed\sto\suse\sthis\sfield\sanyway)\sand\saccommodate\s<tt>spaceAvl\s==\sINT_MAX\s+\s1u</tt>;\salternatively,\sit\sseems\spossible\sto\sonly\ssupport\sup\sto\s<tt>length\s==\sINT_MAX\s-\s1</tt>\sthrough\sadditional\s<tt>Tcl_Panic()</tt>\susage\s(since\sthe\saffected\sfunctions\scannot\sindicate\san\serror\sto\sthe\scaller,\sand\spanicking\sduring\sthese\sfunctions\sis\salready\spossible\swhen\s<tt>ckalloc()</tt>\sor\s<tt>ckrealloc()</tt>\sfail).\sIt\swould\salso\sinclude\sdeciding\swhat\sto\sdo\swhen\sa\s<tt>Tcl_DString</tt>\sof\smaximum\spossible\s<tt>length</tt>\sstill\sisn’t\slarge\senough\sto\saccommodate\sa\sresult\s(panicking\sagain\sseems\slike\san\soption,\ssince\sthat\scan\salready\shappen\sdue\sto\smemory\sallocation\sfailure).
J foundin 8.6.12
J is_private 0
J login chrstphrchvz
J priority 5\sMedium
J resolution None
J severity Minor
J status Open
J submitter chrstphrchvz
J subsystem 11.\sConversions\sfrom\sString
J title multiple\sissues\sin\sTcl_DString\sfunctions
J type Bug
K 1bd796d9c2915891af1afe3f99a3db7bc1ed8a0a
U chrstphrchvz
Z 61a541d05faca36edd6e55364b480ed9