From aeaf62fa86b1e8e303e029870cf9060d3b0700a1 Mon Sep 17 00:00:00 2001 From: 198wmj <19829676829@139.com> Date: Wed, 24 Jun 2026 01:08:26 +0800 Subject: [PATCH] fix: resolve postgres startup message length type mismatch and uint underflow OOM risk (#10065) * fix: resolve postgres startup message length type mismatch and uint underflow OOM risk * Update weed/server/postgres/server.go Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: wangmeijuan <542204218@qq.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- weed/server/postgres/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/weed/server/postgres/server.go b/weed/server/postgres/server.go index 1ac4d8b3e..51c9fe1e3 100644 --- a/weed/server/postgres/server.go +++ b/weed/server/postgres/server.go @@ -388,7 +388,13 @@ func (s *PostgreSQLServer) handleStartup(session *PostgreSQLSession) error { return fmt.Errorf("failed to read message length during startup: %v", err) } - msgLength := binary.BigEndian.Uint32(length) - 4 + msgTotalLen := binary.BigEndian.Uint32(length) + // Prevent unsigned underflow and OOM by checking total message length first + if msgTotalLen < 8 { + return fmt.Errorf("startup message too short: %d bytes", msgTotalLen) + } + + msgLength := msgTotalLen - 4 if msgLength > 10000 { // Reasonable limit for startup messages return fmt.Errorf("startup message too large: %d bytes", msgLength) }