Skip to content
Tcl Source Code Artifact [7737c2ef13]
Login

Artifact [7737c2ef13]

Artifact 7737c2ef136c863601bf6a2de230e77bf1ddbb4ff17f11f6258fa905ad9e0699:

Ticket change [7737c2ef13] - New ticket [409a4e5f2853644f|409a4e5f28] <i>Abstract-list hooks: lpop and join/lset crash, lindex reads before buffer with a negative index</i>. by rocketship98 on 2026-10-18 10:23:43.
D 2026-10-18T10:23:43.599
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment These\swere\sfound\sby\sClaude\sdoing\smutation\stesting\sof\sthe\sTcl_ObjType\sv2\shooks.\sI\stested\seach\sand\sgot\seither\sseg\sfaults\sor\sthe\swrong\sinfo\sas\sdetailed\sbelow.\sThe\sdiagnosis\sis\sClaudes.\s\r\n\r\nThey\suse\sthe\r\ntest-only\s`lstring`\stype\s(tclTestABSList.c),\sso\sthey\sneed\sa\stcltest\sshell\sbuilt\r\nfrom\sthe\sTcl\ssources\s(`make\stcltest`,\sthen\s`./tcltest`).\sStart\sa\sfresh\sshell\sfor\r\neach\ssnippet,\sbecause\sF1\sto\sF3\scrash\sthe\sshell.\sNo\sshipped\stype\shas\sa\r\nsetElementProc,\sso\sF1\sand\sF3\sonly\saffect\sextensions\sthat\ssupply\sthat\shook.\r\nF1\sto\sF4\swere\seach\srun\son\sa\stcltest\s9.1.1\sbuild\sand\sreproduce\sas\sdescribed.\r\n\r\n**F1.\slpop\ssegfaults\s(tclCmdIL.c\s~2670-2682).**\r\n\r\n\s\s\s\sset\sl\s[lstring\sabcd];\slpop\sl\s1;\sset\sr\s[list\s$l];\sset\sl\s5;\slappend\sr\sx;\sputs\s$r\r\n\r\nResult:\ssegfault.\s(On\sanother\sbuild\sit\sprinted\s`{}\sx`\sinstead\sof\sthe\scorrect\r\n`{a\sc\sd}\sx`,\sso\sthe\ssymptom\sdepends\son\smemory\sreuse.)\r\nCause\s(from\sreading\sthe\ssource,\snot\sconfirmed\sin\sa\sdebugger):\sthe\r\nsetElementProc\sbranch\scalls\sTclUndoRefCount(listPtr)\swithout\sa\sprior\r\nTcl_IncrRefCount\s(tclObj.c:\s"The\scaller\smust\shave\spreviously\sincremented\sthe\r\nrefCount"),\sso\sthe\sreference\scount\sends\sup\sone\stoo\slow.\slset\s(tclCmdIL.c\s~4295)\r\ndoes\sincrement.\r\n\r\n**F2.\sjoin\sof\sa\sone-element\slist\ssegfaults\s(tclCmdIL.c\s~2169-2196).**\r\nFor\sa\stype\swith\sgetElementsProc\sbut\sno\sindexProc\s(the\smanual\srequires\sonly\r\nlengthProc):\r\n\r\n\s\s\s\sjoin\s[lstring\s-not\sINDEX\sa]\s:\r\n\r\nResult:\ssegfault.\sThe\s`listLen\s>\s1`\stest\sskips\sgetElementsProc\sfor\slength\s1,\sand\r\nthe\ssingle-element\sbranch\sthen\scalls\sTclObjTypeIndex,\swhich\shas\sno\sproc.\r\n\r\n**F3.\slset\swith\sa\slist\sof\sindices\ssegfaults,\scompiled\sand\suncompiled.**\r\n\r\n\s\s\s\sset\sl\s[lstring\sabc];\slset\sl\s{1\s0}\sX\r\n\r\nResult:\ssegfault.\sPath:\sTcl_LsetObjCmd\s->\sTclLsetList\s->\sTclLsetFlat\s->\r\nTcl_ListObjGetElements\s->\sSetListFromAny\s->\sTcl_GetStringFromObj.\r\n`lset\sl\s1\s0\sX`\sis\srefused\spolitely;\sthe\sone-argument\sindex\slist\sis\snot.\r\n(Possibly\srelated\sto\sticket\s1,\sas\sboth\sgo\sthrough\sTclLsetFlat.)\r\n\r\n**F4.\slindex\swith\sa\snon-literal\snegative\sindex\s(INST_LIST_INDEX,\stclExecute.c\s~5037-5047).**\r\nThe\snegative\sindex\sis\spassed\sto\sthe\stype's\sindexProc,\sunlike\sthe\sliteral-index\r\ninstruction\sand\sTcl_ListObjIndex.\slstring's\sindexProc\sdoes\snot\scheck\sit\seither\r\nand\sreads\sthe\sbyte\sbefore\sits\sbuffer:\r\n\r\n\s\s\s\sproc\sidx\s{l\si}\s{lindex\s$l\s$i}\r\n\s\s\s\sstring\slength\s[idx\s[lstring\sabcde]\s-1]\r\n\s\s\s\sbinary\sencode\shex\s[encoding\sconvertto\sutf-8\s[idx\s[lstring\sabcde]\s-1]]\r\n\r\nExpected:\s0\s(empty\sstring).\sActual:\s1,\sand\sthe\shex\sis\s00,\sa\sNUL\sbyte\sread\sfrom\r\nbefore\sthe\sbuffer.\sThe\svalue\sof\sthat\sbyte\sdepends\son\smemory\scontents.\r\n\r\nA\stest\sfile\scovering\sthese\s(47\stests)\sis\savailable\son\srequest.
J foundin 9.1.1\strunk\s(commit\s2fa2d8bbd9)
J is_private 0
J login rocketship98
J priority 5\sMedium
J private_contact b5d6d6e631648ab8145961ecf2e3fa064603ac0a
J resolution None
J severity Important
J status Open
J submitter rocketship98
J subsystem 14.\sList\sObject
J title Abstract-list\shooks:\slpop\sand\sjoin/lset\scrash,\slindex\sreads\sbefore\sbuffer\swith\sa\snegative\sindex
J type Bug
K 409a4e5f2853644f6e78dce8f8d0d68a0d393dde
U rocketship98
Z 7c005434e454590a6d15814e5a0bcffe