From c1f9fd84065e60d6813aeb0e13c51b94986d9ec3 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Sat, 2 Jan 2016 13:33:27 +0100 Subject: [PATCH] Fix heap corruption when collecting region layers The collecting could overflow the neighbours array due to a missing boundary check. Fix #30 --- Recast/Source/RecastLayers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Recast/Source/RecastLayers.cpp b/Recast/Source/RecastLayers.cpp index b9b416b..6b02204 100644 --- a/Recast/Source/RecastLayers.cpp +++ b/Recast/Source/RecastLayers.cpp @@ -258,7 +258,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf, const int ay = y + rcGetDirOffsetY(dir); const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, dir); const unsigned char rai = srcReg[ai]; - if (rai != 0xff && rai != ri) + if (rai != 0xff && rai != ri && regs[ri].nneis < RC_MAX_NEIS) addUnique(regs[ri].neis, regs[ri].nneis, rai); } }