From a9fd1d2482f5a39dddaef3ed82e3e0ffe30a6798 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 25 May 2025 22:30:39 +0200 Subject: [PATCH] [GEN][ZH] Prevent unlikely buffer overrun while writing to 'newPts' in PolygonTrigger::reallocate() --- .../Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp | 4 ++++ .../Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index e209263398..2841377d9e 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -95,6 +95,10 @@ void PolygonTrigger::reallocate(void) { DEBUG_ASSERTCRASH(m_numPoints <= m_sizePoints, ("Invalid m_numPoints.")); if (m_numPoints == m_sizePoints) { + if (m_sizePoints > INT_MAX / 2) { + DEBUG_CRASH(("Too many points to allocate.")); + return; + } // Reallocate. m_sizePoints += m_sizePoints; ICoord3D *newPts = NEW ICoord3D[m_sizePoints]; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp index 5e1dc0fb65..a0878a76b4 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Map/PolygonTrigger.cpp @@ -97,6 +97,10 @@ void PolygonTrigger::reallocate(void) { DEBUG_ASSERTCRASH(m_numPoints <= m_sizePoints, ("Invalid m_numPoints.")); if (m_numPoints == m_sizePoints) { + if (m_sizePoints > INT_MAX / 2) { + DEBUG_CRASH(("Too many points to allocate.")); + return; + } // Reallocate. m_sizePoints += m_sizePoints; ICoord3D *newPts = NEW ICoord3D[m_sizePoints];