From e5d2f734b8cb7c5cf4d25d979c5e829f7da1a10c Mon Sep 17 00:00:00 2001
From: reshke <reshke@double.cloud>
Date: Mon, 6 Oct 2025 17:27:25 +0000
Subject: [PATCH v1 4/4] Reduce GIST_MAX_SPLIT_PAGES to some sane limit.

There is a limit for of backup blocks that single wal
record can reference (XLR_MAX_BLOCK_ID). Enforce and check
this limit for GiST page split.
---
 src/include/access/gist_private.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index 0a38d1ea4dc..9963a4bfd18 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -22,6 +22,7 @@
 #include "storage/buffile.h"
 #include "utils/hsearch.h"
 #include "access/genam.h"
+#include "access/xlogrecord.h"
 
 /*
  * Maximum number of "halves" a page can be split into in one operation.
@@ -36,7 +37,14 @@
  * so if you raise this higher than that limit, you'll just get a different
  * error.
  */
-#define GIST_MAX_SPLIT_PAGES		75
+#define GIST_MAX_SPLIT_PAGES		25
+
+/* Enforce the size rule given in the comment above. +1 because zeroth backup block
+* it used for clearing follow-right pointer, blocks 1...GIST_MAX_SPLIT_PAGES for 
+* split pages */
+StaticAssertDecl(GIST_MAX_SPLIT_PAGES + 1 <= XLR_MAX_BLOCK_ID,
+				 "GIST_MAX_SPLIT_PAGES exceeds maximum allowed number of backup blocks");
+
 
 /* Buffer lock modes */
 #define GIST_SHARE	BUFFER_LOCK_SHARE
-- 
2.43.0

