From: Nathan Bossart Date: Thu, 27 Apr 2023 20:43:48 +0000 (-0700) Subject: Prevent underflow in KeepLogSeg(). X-Git-Tag: REL_16_BETA1~125 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b72623671d9c0ead4ac219c69762246073fe2185;p=thirdparty%2Fpostgresql.git Prevent underflow in KeepLogSeg(). The call to XLogGetReplicationSlotMinimumLSN() might return a greater LSN than the one given to the function. Subsequent segment number calculations might then underflow, which could result in unexpected behavior when removing or recyling WAL files. This was introduced with max_slot_wal_keep_size in c655077639. To fix, skip the block of code for replication slots if the LSN is greater. Reported-by: Xu Xingwang Author: Kyotaro Horiguchi Reviewed-by: Junwang Zhao Discussion: https://postgr.es/m/17903-4288d439dee856c6%40postgresql.org Backpatch-through: 13 --- diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 63481d826f7..bc5a8e05697 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7459,7 +7459,7 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) * max_slot_wal_keep_size. */ keep = XLogGetReplicationSlotMinimumLSN(); - if (keep != InvalidXLogRecPtr) + if (keep != InvalidXLogRecPtr && keep < recptr) { XLByteToSeg(keep, segno, wal_segment_size);