agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improving handling of oversized records in xlogreader.c
Date: Tue, 04 Aug 2026 21:53:49 +0000
Message-ID: <E1wrN53-00000000DbJ-13xL@gemulon.postgresql.org> (raw)

Improving handling of oversized records in xlogreader.c

XLogRecordAssemble() refuses records larger than XLogRecordMaxSize when
generating records, but the reader-side only checked a minimal number
for xl_tot_len.

A crafted multi-page record with xl_tot_len near UINT32_MAX could bypass
the contrecord length checks, overflow allocate_recordbuf()'s size math,
and corrupt memory during reassembly (or hit related asserts under
cassert).

xlogreader.c is updated to check that the received record is never
larger than XLogRecordMaxSize, when first receiving the first bytes of
xl_tot_len, then again when validating the record header.

WAL is a source of data trusted by the server, with CRC32 checksums
providing a level of protection before replaying the records if data is
corrupted.  These limits could be internally reached only with crafted
WAL records, which is something that analyzers (named as LLMs) like
complaining about these days.

039_end_of_wal.pl is adjusted according to the new maximum limit, a test
for XLogRecordMaxSize is added.

Author: David Karapetyan <dkarapetyan@gmail.com>
Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Discussion: https://postgr.es/m/CALmTjZBddzeGVU2o1JNZb3mPvV68PqDskWPAUQBVb-35yVkiwA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/18992dc9d98022a43831da8e1868abf3ce5cd66a

Modified Files
--------------
src/backend/access/transam/xlogreader.c | 33 +++++++++++++++++++++++++++++++--
src/test/recovery/t/039_end_of_wal.pl   | 33 +++++++++++++++++++++++----------
2 files changed, 54 insertions(+), 12 deletions(-)



Message-ID: <E1wrN53-00000000DbJ-13xL@gemulon.postgresql.org>
Permalink:  ../E1wrN53-00000000DbJ-13xL@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wrN53-00000000DbJ-13xL@gemulon.postgresql.org

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Improving handling of oversized records in xlogreader.c
  In-Reply-To: <E1wrN53-00000000DbJ-13xL@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox