From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB
Date: Mon, 02 Nov 2026 01:46:16 +0000
Message-ID: <E1xNh7o-00000001jJl-07jn@gemulon.postgresql.org> (raw)
Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB.
In xmltotext_with_options(), xmlSaveClose() frees the save context
unconditionally, but ctxt was only reset to NULL on the error branch.
When the close succeeded and a later step threw an error -- typically,
cstring_to_text_with_len() rejecting a result larger than MaxAllocSize
-- control reached the PG_CATCH block with ctxt still pointing at the
freed context, so xmlSaveClose() was called a second time on freed
memory and crashed the backend.
Author: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/bbadb6b2-d226-41a1-ace3-e0eb20648f58@uni-muenster.de
Backpatch-through: 16
Branch
------
REL_18_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/f10500777b2a4d3da6d8d1dd0602e542a4300410
Modified Files
--------------
src/backend/utils/adt/xml.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB
In-Reply-To: <E1xNh7o-00000001jJl-07jn@gemulon.postgresql.org>
References: <E1xNh7o-00000001jJl-07jn@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox