Skip to content
Tcl Source Code Artifact [f60cd72d52]
Login

Artifact [f60cd72d52]

Artifact f60cd72d52bb96cc3cb23f56d339f78f3da9c157bd68a0c58d6b1fdb7e170da9:

Ticket change [f60cd72d52] - New ticket [a6029ee50552e4e8|a6029ee505] <i>regexp hangs with backreferences when a possible empty match fails</i>. by serhiy.storchaka on 2026-10-10 18:47:21.
D 2026-10-10T18:47:21.262
J cmimetype text/x-fossil-wiki
J comment These\snever\sreturn:\n<verbatim>\nregexp\s{(b*)a\\1|\\1}\sba\s\s\s\s\s\s;#\sshould\sreturn\s1\s(matches\s"a")\nregexp\s{$()|^\\1}\sa\s\s\s\s\s\s\s\s\s\s;#\sshould\sreturn\s0\nregexp\s{..\s()|\\1}\sa\s\s\s\s\s\s\s\s\s;#\sshould\sreturn\s0\nregexp\s{()*\\1}\sa\s\s\s\s\s\s\s\s\s\s\s\s;#\sshould\sreturn\s1\n</verbatim>\nThe\sfirst\sone\swas\sfound\sby\scomparing\srandom\spatterns\swith\sbackreferences\sagainst\sPostgreSQL;\sthe\sother\sthree\sare\sfrom\sthe\sPostgreSQL\sregression\stests.\n\n<tt>complicatedFindLoop()</tt>\sasks\sthe\ssearch\sDFA\sfor\sthe\searliest\spossible\smatch\send\s<tt>close</tt>,\stries\severy\sstart\spoint\sup\sto\sit,\sand\swhen\sall\sof\sthem\sfail,\ssearches\sagain\sfrom\sthe\ssame\s<tt>close</tt>.\sThe\sDFA\streats\sa\sbackreference\sas\smatching\sanything,\sso\sit\sreports\sa\spossible\sempty\smatch\sthere\sagain,\sand\sthe\sloop\snever\sadvances.\sThis\sis\sonly\spossible\swith\sbackreferences.\sIt\sstarted\swith\sthe\sfix\sfor\s[6585b21ca8]\sin\s8.6.1;\s<tt>()*\\1</tt>\shangs\ssince\s8.6.5.\n\nPostgreSQL\sfixed\sthis\sin\s2015,\safter\sthe\ssame\schange,\sin\s[https://github.com/postgres/postgres/commit/f2c4ffc330|commit\sf2c4ffc330]:\sadvance\s<tt>close</tt>\safter\sa\sfailed\srange\s(<tt>close++</tt>),\sand\sin\s<tt>citerdissect()</tt>\stry\sa\sreal\siteration\sbefore\saccepting\szero\siterations\sof\san\sempty\smatch,\sso\sthat\s<tt>()*\\1</tt>\smatches\sinstead\sof\sfailing.\sThis\sfix\swas\snot\sincluded\sin\sthe\sregexp\sbundle\s[497b93405b].\sWith\sboth\schanges\sported,\sall\sfour\sexamples\sgive\sthe\sPostgreSQL\sresults,\sand\sthe\sregexp\stests\spass.
J foundin 8.6.18,\s9.0.5,\s9.1.0
J login serhiy.storchaka
J priority 5\sMedium
J resolution None
J severity Important
J status Open
J submitter serhiy.storchaka
J subsystem 43.\sRegexp
J title regexp\shangs\swith\sbackreferences\swhen\sa\spossible\sempty\smatch\sfails
J type Bug
K a6029ee50552e4e89fd57a4a18c83379b64da46c
U serhiy.storchaka
Z 47901b14aab32ef872fa6edea7073f33