App: Coverity fixes

This commit is contained in:
Chris Hennes
2025-03-02 23:21:30 -06:00
committed by Benjamin Nauck
parent d850e87567
commit c1ada6bc40
11 changed files with 41 additions and 38 deletions

View File

@@ -258,7 +258,8 @@ ElementMapPtr ElementMap::restore(::App::StringHasherRef hasherRef, std::istream
std::vector<ElementMapPtr> childMaps;
count = 0;
if (!(stream >> tmp >> count) || tmp != "MapCount" || count == 0) {
constexpr int practicalMaximum {1 << 30 / sizeof(ElementMapPtr)}; // a 1GB child map vector: almost certainly a bug
if (!(stream >> tmp >> count) || tmp != "MapCount" || count == 0 || count > practicalMaximum) {
FC_THROWM(Base::RuntimeError, msg); // NOLINT
}
childMaps.reserve(count - 1);
@@ -285,6 +286,10 @@ ElementMapPtr ElementMap::restore(::App::StringHasherRef hasherRef,
if (!(stream >> tmp >> index >> id >> typeCount) || tmp != "ElementMap") {
FC_THROWM(Base::RuntimeError, msg); // NOLINT
}
constexpr int maxTypeCount(1000);
if (typeCount < 0 || typeCount > maxTypeCount) {
FC_THROWM(Base::RuntimeError, "Bad type count in element map, ignoring map"); // NOLINT
}
auto& map = _idToElementMap[id];
if (map) {