pgsql: Improving handling of oversized records in xlogreader.c

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Improving handling of oversized records in xlogreader.c
Date: 2026-08-04 21:53:49
Message-ID: E1wrN53-00000000DbJ-13xL@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)gmail(dot)com>
Author: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Melanie Plageman 2026-08-04 22:06:59 pgsql: Silence Coverity warning about unused visibilitymap_clear() resu
Previous Message Masahiko Sawada 2026-08-04 20:41:14 pgsql: Add comments to uuid_extract_timestamp().