[PATCH] Perform check for oversized WAL record before calculating record CRC

Started by Sergey Fukanchik12 months ago3 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t52250
psql -h localhost -U postgres

Built from patchset v3 (message #3), August 24, 2026 at 02:44 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t52250_3 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t52250_3 && git checkout t52250_3

Patchset v3 (message #3) is on t52250_3

Jump to latest
#1Sergey Fukanchik
s.fukanchik@postgrespro.ru

Hi Postgres hackers,
I found a case where CRC of 1Gb block is calculated first and then
immediately
discarded.

There is a limit on WAL record size - XLogRecordMaxSize. If the record
being inserted is larger than that, it is discarded and error is reported:

ERROR:  oversized WAL record
DETAIL:  WAL record would be 1069547521 bytes (of maximum 1069547520 bytes)

However, crc of record data is calculated before the record size is
validated,
and in case of oversized record this crc is not used anywhere.

It is surely a minor issue, but might be worth fixing. I'm proposing a
patch.
Since this situation is not covered by any tests I also included a test case
for failing on huge WAL records.
---
Sergey Fukanchik

Attachments:

0001-Perform-check-for-oversized-WAL-record-before-calcul.patchtext/x-patch; charset=UTF-8; name=0001-Perform-check-for-oversized-WAL-record-before-calcul.patchDownload+23-15
#2Andrey Borodin
amborodin@acm.org
In reply to: Sergey Fukanchik (#1)
Re: [PATCH] Perform check for oversized WAL record before calculating record CRC

On 6 Sep 2025, at 16:00, Sergey Fukanchik <s.fukanchik@postgrespro.ru> wrote:

<0001-Perform-check-for-oversized-WAL-record-before-calcul.patch>

Hi Sergey!

It seems to me reasonable to move size check above CRC computation. However, it seems suspicious to me to run a test that allocates 1Gb in `make check`. Maybe, there are places that are not exercised too often. Perhaps recovery tests or something like that.

Best regards, Andrey Borodin.

#3Sergey Fukanchik
s.fukanchik@postgrespro.ru
In reply to: Andrey Borodin (#2)
Re: [PATCH] Perform check for oversized WAL record before calculating record CRC

It seems to me reasonable to move size check above CRC computation. However, it seems suspicious to me to run a test that allocates 1Gb in `make check`. Maybe, there are places that are not exercised too often. Perhaps recovery tests or something like that.

Hi Andrey,

I share your concern about memory consumption and also agree recovery
tests look like the right place for this test.

So I split the patch into two - the change proper and the converted TAP
test, guarded by PG_TEST_EXTRA. Attaching both patches.

---

Sergey

Attachments:

t52250_3
v2-0001-Perform-check-for-oversized-WAL-record-before-cal.patchtext/x-patch; charset=UTF-8; name=v2-0001-Perform-check-for-oversized-WAL-record-before-cal.patchDownload+13-14
v2-0002-Add-a-TAP-test-for-oversized-WAL-records.patchtext/x-patch; charset=UTF-8; name=v2-0002-Add-a-TAP-test-for-oversized-WAL-records.patchDownload+50-1