Re: [PATCH] contrib/xml2: backend crash in xpath_nodeset() on the namespace axis

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Andrey Chernyy <andrey(dot)cherny(at)tantorlabs(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] contrib/xml2: backend crash in xpath_nodeset() on the namespace axis
Date: 2026-06-11 01:48:30
Message-ID: aioT7ui_ZJ9RMlfM@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Jun 11, 2026 at 03:14:36AM +0300, Andrey Chernyy wrote:
> Reproduced on master; the same unguarded xmlNodeDump() call in
> pgxmlNodeSetToText() is present on every supported back-branch (REL_18
> through REL_14).
>
> Patch attached: render XML_NAMESPACE_DECL nodes with
> xmlXPathCastNodeToString() like xpath_table() does. The repro then
> returns the namespace text, ordinary node-set output is unchanged, and
> the xml2 regression test passes.

Thanks for the report, that looks about right to fix the way you are
doing in xml2. Some tests and we should be good.

Hmm. We have a second caller of xmlNodeDump() in the core backend
code in adt/xml.c, leading to a confusing error if I try to use a
namespace:
=# select xpath('//namespace::*', '<root xmlns:foo="http://example.com"/>'::xml);
ERROR: 53200: could not copy node
CONTEXT: SQL function "xpath" statement 1
LOCATION: xml_ereport, xml.c:2082

It looks to me that we should fallback to xmlXPathCastNodeToString()
when dealing with a NAMESPACE_DECL. The attached patch leads me to
the following result, that looks much better:
=# select xpath('//namespace::*', '<root xmlns:foo="http://example.com"/>'::xml);
xpath
-----------------------------------------------------------
{http://www.w3.org/XML/1998/namespace,http://example.com}
(1 row)

What do you think? That also deserves a backpatch to me, even if it
is less worse than the xml2 crash you have reported.

I have grouped this fix with your patch in the attached. Both still
need some tests. Each fix deserves its own commit, that's just a
quick FYI version.
--
Michael

Attachment Content-Type Size
v2-0001-xml2-don-t-crash-on-namespace-nodes-in-xpath_node.patch text/plain 2.4 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Fujii Masao 2026-06-11 03:31:28 Re: BUG #18876: HINT messages for mxid wrap-around say "drop stale slots", but that may not be appropriate
Previous Message Tender Wang 2026-06-11 01:03:22 Re: BUG #19517: Eager Aggregation produces wrong count(*) when pushed into RHS of Hash Semi Join