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>
This commit is contained in:
198wmj
2026-06-23 10:08:26 -07:00
committed by GitHub
co-authored by gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> wangmeijuan gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
parent b0bad761ff
commit aeaf62fa86
+7 -1
View File
@@ -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)
}