From 3166fd05f49e08d01c654d8a66134ae0b35f2a45 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Sun, 9 Apr 2023 14:43:51 +0400 Subject: [PATCH] Handle array exceed limit potential crash --- lib/mapping/CCampaignHandler.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mapping/CCampaignHandler.cpp b/lib/mapping/CCampaignHandler.cpp index 186e62c6e..3253a0d00 100644 --- a/lib/mapping/CCampaignHandler.cpp +++ b/lib/mapping/CCampaignHandler.cpp @@ -302,7 +302,10 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader, if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "creature", k.String())) { int creId = identifier.get(); - ret.monstersKeptByHero[creId / 8] |= (1 << creId % 8); + if(creId >= ret.monstersKeptByHero.size()) + logGlobal->warn("VCMP Loading: creature %s with id %d isn't supported yet", k.String(), creId); + else + ret.monstersKeptByHero[creId / 8] |= (1 << creId % 8); } else logGlobal->warn("VCMP Loading: keepCreatures contains unresolved identifier %s", k.String()); @@ -312,7 +315,10 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader, if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "artifact", k.String())) { int artId = identifier.get(); - ret.artifsKeptByHero[artId / 8] |= (1 << artId % 8); + if(artId >= ret.artifsKeptByHero.size()) + logGlobal->warn("VCMP Loading: artifact %s with id %d isn't supported yet", k.String(), artId); + else + ret.artifsKeptByHero[artId / 8] |= (1 << artId % 8); } else logGlobal->warn("VCMP Loading: keepArtifacts contains unresolved identifier %s", k.String());