<i> lset with 2+ indices on an unshared lseq list is a use-after-free (crash)</i>.
by
.
D 2026-10-18T09:48:35.779
J assignee nobody
J closer nobody
J cmimetype text/x-markdown
J comment \s\s\s\sset\sl\s[lseq\s5]\r\n\s\s\s\slset\sl\s1\s0\sX\r\n\s\s\s\sfor\s{set\si\s0}\s{$i\s<\s2000}\s{incr\si}\s{lappend\sz\s[list\s$i]}\r\n\r\nOn\san\s-O2\sbuild\sthe\sloop\ssegfaults\s(TclThreadAllocObj,\sobject\spool\scorrupted).\r\nOn\sa\s`--enable-symbols=mem`\sbuild\sit\spanics\sat\sonce:\r\n`Tcl_DbIncrRefCount:\sTcl_Obj\sallocated\sin\sanother\sthread`,\sfrom\r\nTclListObjSetElement\s(tclListObj.c:3289)\scalled\sby\sTclLsetFlat\s(tclListObj.c:3108).\r\n\r\nSame\swith\s`lset\sl\s{1\s0}\sX`,\swith\s`lreverse\s[lseq\s5]`\sand\s`lrange\s[lseq\s10]\s2\s6`\r\nas\sthe\slist,\sand\safter\sa\s`lindex\s$l\s1`\shas\srun\son\sthe\slseq\slist.\r\nNot\saffected:\ssingle-index\slset,\snative\slists,\slrepeat.\r\n\r\nCause:\sin\sTclLsetFlat,\s`elemPtrs`\scomes\sfrom\sTcl_ListObjGetElements\son\sthe\r\narithseries\slist,\si.e.\sits\scached\selement\sarray,\swith\sno\sreference\sadded.\r\n`subListObj\s=\selemPtrs[index]`\sis\sthen\spassed\sto\r\nTclListObjSetElement(parentList,\sindex,\ssubListObj).\sThat\scall\sconverts\sthe\r\nabstract\slist\sto\sa\snative\slist\s(SetListFromAny,\sbuilding\snew\selements\sthrough\r\nindexProc)\sand\sfrees\sthe\sarithseries\sinternal\srep,\sincluding\sthe\scache,\sso\r\n`subListObj`\s(refCount\s1,\sowned\sonly\sby\sthe\scache)\sis\sfreed\sbefore\sit\sis\sstored.\r\nA\sfix\scould\sbe\sto\stake\sa\sreference\son\ssubListObj\saround\sthe\sconversion,\sor\sto\r\nconvert\sparentList\sto\sa\snative\slist\sbefore\sreading\selemPtrs.\r\n\r\nFound\sby\smutation\stesting\sof\sthe\sabstract-list\scode\s(using\sclaude,\sso\scan't\ssay\si\sunderstand\shis\sreasoning).\sBut\sit\scrashes\smy\swindows\swish91.exe
J foundin trunk\s2fa2d8bbd9
J is_private 0
J login rocketship98
J priority 5\sMedium
J private_contact b5d6d6e631648ab8145961ecf2e3fa064603ac0a
J resolution None
J severity Severe
J status Open
J submitter rocketship98
J subsystem 14.\sList\sObject
J title \slset\swith\s2+\sindices\son\san\sunshared\slseq\slist\sis\sa\suse-after-free\s(crash)
J type Bug
K 526b01c0b9921b90618f82c398dc2684a60a053a
U rocketship98
Z 37997ae6899f1753c7bfc76c7eae7c6e