From 396f3f40de2f6b106f4341db03f03129b3d8d081 Mon Sep 17 00:00:00 2001
From: Sehrope Sarkuni <sehrope@jackdb.com>
Date: Wed, 10 Jun 2026 08:23:53 -0400
Subject: [PATCH 3/4] Fix off-by-one in pgwin32_select event array

The events array must hold up to 2*FD_SETSIZE socket events plus the
signal event. With full disjoint read and write fd sets the signal
event was written one element past the end of the array.
---
 src/backend/port/win32/socket.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/backend/port/win32/socket.c b/src/backend/port/win32/socket.c
index 3aaf971e973..24666ea3c9d 100644
--- a/src/backend/port/win32/socket.c
+++ b/src/backend/port/win32/socket.c
@@ -516,9 +516,10 @@ pgwin32_send(SOCKET s, const void *buf, int len, int flags)
 int
 pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout)
 {
-	WSAEVENT	events[FD_SETSIZE * 2]; /* worst case is readfds totally
-										 * different from writefds, so
-										 * 2*FD_SETSIZE sockets */
+	WSAEVENT	events[FD_SETSIZE * 2 + 1]; /* worst case is readfds totally
+											 * different from writefds, so
+											 * 2*FD_SETSIZE sockets, plus one
+											 * for the signal event */
 	SOCKET		sockets[FD_SETSIZE * 2];
 	int			numevents = 0;
 	int			i;
-- 
2.48.1

