pgsql: Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB
Date: 2026-11-02 01:46:15
Message-ID: E1xNh7n-00000001jJh-43F5@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)jones(at)uni-muenster(dot)de>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/bbadb6b2-d226-41a1-ace3-e0eb20648f58@uni-muenster.de
Backpatch-through: 16

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/01131ca43bbf798be6ec237a33f6bef67bede888

Modified Files
--------------
src/backend/utils/adt/xml.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-11-02 01:46:16 pgsql: Fix double-free when XMLSERIALIZE(... INDENT) output exceeds 1GB
Previous Message Richard Guo 2026-11-02 01:33:59 pgsql: Fix wrong results from Memoize with a Param inside a cache key