1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00

Improve safety of NVPP ESM records

This commit is contained in:
Andrei Kortunov 2023-08-01 10:39:34 +04:00
parent 1d207ed318
commit 4e531524be

View file

@ -257,8 +257,13 @@ void ESM4::Navigation::load(ESM4::Reader& reader)
break; break;
} }
total -= 10; // HACK if (total >= 10)
std::uint32_t node; total -= 10; // HACK
else
throw std::runtime_error("expected total amount of chunks >= 0xa");
std::uint32_t node = 0;
bool nodeFound = false;
for (std::uint32_t i = 0; i < total; ++i) for (std::uint32_t i = 0; i < total; ++i)
{ {
std::vector<FormId> preferredPaths; std::vector<FormId> preferredPaths;
@ -267,6 +272,7 @@ void ESM4::Navigation::load(ESM4::Reader& reader)
{ {
reader.get(node); reader.get(node);
reader.get(count); reader.get(count);
nodeFound = true;
} }
if (count > 0) if (count > 0)
{ {
@ -274,6 +280,9 @@ void ESM4::Navigation::load(ESM4::Reader& reader)
for (FormId& value : preferredPaths) for (FormId& value : preferredPaths)
reader.getFormId(value); reader.getFormId(value);
} }
if (!nodeFound)
throw std::runtime_error("node not found");
mPreferredPaths.push_back(std::make_pair(node, preferredPaths)); mPreferredPaths.push_back(std::make_pair(node, preferredPaths));
#if 0 #if 0
std::cout << "node " << std::hex << node // FIXME: debugging only std::cout << "node " << std::hex << node // FIXME: debugging only