From 7156e31d14f1b2b37ee3b82a5ca4a8c69bbcf3a3 Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Wed, 8 Apr 2026 08:47:25 +0200
Subject: [PATCH v1] Limit minimum allowed segsize-blocks in autoconf/meson to
 avoid blowing up tests

---
 configure    | 4 ++++
 configure.ac | 4 ++++
 meson.build  | 3 +++
 3 files changed, 11 insertions(+)

diff --git a/configure b/configure
index f66c1054a7a..af49854e7df 100755
--- a/configure
+++ b/configure
@@ -3796,6 +3796,10 @@ if test $segsize_blocks -ne 0 -a $segsize -ne 1; then
 $as_echo "$as_me: WARNING: both --with-segsize and --with-segsize-blocks specified, --with-segsize-blocks wins" >&2;}
 fi
 
+if test $segsize_blocks -ne 0 -a $segsize_blocks -lt 6; then
+  as_fn_error $? "too small segsize-blocks specified" "$LINENO" 5
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for segment size" >&5
 $as_echo_n "checking for segment size... " >&6; }
 if test $segsize_blocks -eq 0; then
diff --git a/configure.ac b/configure.ac
index 8d176bd3468..c01bfceb7a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -290,6 +290,10 @@ if test $segsize_blocks -ne 0 -a $segsize -ne 1; then
   AC_MSG_WARN([both --with-segsize and --with-segsize-blocks specified, --with-segsize-blocks wins])
 fi
 
+if test $segsize_blocks -ne 0 -a $segsize_blocks -lt 6; then
+  AC_MSG_ERROR([too small segsize-blocks specified])
+fi
+
 AC_MSG_CHECKING([for segment size])
 if test $segsize_blocks -eq 0; then
   # this expression is set up to avoid unnecessary integer overflow
diff --git a/meson.build b/meson.build
index be97e986e5d..d77343f5a64 100644
--- a/meson.build
+++ b/meson.build
@@ -512,6 +512,9 @@ if get_option('segsize_blocks') != 0
   if get_option('segsize') != 1
     warning('both segsize and segsize_blocks specified, segsize_blocks wins')
   endif
+  if get_option('segsize_blocks') < 6
+    error('too small segsize_blocks specified')
+  endif
 
   segsize = get_option('segsize_blocks')
 else
-- 
2.43.0

