pg_controldata: Fix possible errors on corrupted pg_control

Alexander Korotkov <akorotkov@postgresql.org>

Commit: c24311c1fed18ebdf0e64f31a8cd86cd3232657b
Author: Alexander Korotkov <akorotkov@postgresql.org>
Date: 2025-02-04T22:46:06Z
Releases: 13.19
pg_controldata: Fix possible errors on corrupted pg_control

Protect against malformed timestamps.  Also protect against negative WalSegSz
as it triggers division by zero:

((0x100000000UL) / (WalSegSz)) can turn into zero in

XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
             segno, WalSegSz);

because if WalSegSz is -1 then by arithmetic rules in C we get
0x100000000UL / 0xFFFFFFFFFFFFFFFFUL == 0.

Author: Ilyasov Ian <ianilyasov@outlook.com>
Author: Anton Voloshin <a.voloshin@postgrespro.ru>
Backpatch-through: 13

Files

PathChange+/−
src/bin/pg_controldata/pg_controldata.c modified +18 −7