model-writtenrun 2989 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Jingzhou Fu reported that an XPath expression containing 100,000 opening parentheses crashed a PostgreSQL backend through stack overflow in libxml2 #1; Erik Wienhold reproduced the failure with libxml2 2.13.3 and pointed to an earlier upstream report #2.
- Tom Lane initially concluded that libxml2's complexity limits failed to catch the case #3, confirmed that all versions he tested crashed #4, and filed a new upstream bug #5.
- Following an upstream response from Nick Wellnhofer, Tom Lane posted a one-call workaround using xmlXPathCtxtCompile and reported that it prevented the crash with sufficiently recent libxml2 versions; he also relayed a suggestion to eliminate separate compilation for expressions evaluated only once #6.
- Tom Lane expanded the workaround to all five compilation calls and added assertions documenting XMLTABLE's required initialization order; he rejected combining compilation and evaluation because that would change user-visible errors, omitted a regression test because pre-2.9.11 libxml2 would fail it, and deferred error-code cleanup #7.
- The thread ended with the completed patch #7, which subsequently landed unchanged apart from rebase offsets as 0206795d25 and was backpatched to all supported versions; protection still requires libxml2 2.9.11 or newer.