From 878d4ddaa7703561232eb17f09e8e6d52f694d29 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sun, 10 Sep 2023 02:45:51 +0300 Subject: [PATCH] Update record pointer loading --- components/nif/recordptr.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/nif/recordptr.hpp b/components/nif/recordptr.hpp index 5b890eec54..eb704dbc21 100644 --- a/components/nif/recordptr.hpp +++ b/components/nif/recordptr.hpp @@ -1,9 +1,10 @@ #ifndef OPENMW_COMPONENTS_NIF_RECORDPTR_HPP #define OPENMW_COMPONENTS_NIF_RECORDPTR_HPP +#include + #include "niffile.hpp" #include "nifstream.hpp" -#include namespace Nif { @@ -39,7 +40,7 @@ namespace Nif assert(index == -2); // Store the index for later - index = nif->getInt(); + index = nif->get(); assert(index >= -1); } @@ -90,12 +91,13 @@ namespace Nif template void readRecordList(NIFStream* nif, RecordListT& list) { - const int length = nif->getInt(); + const std::uint32_t length = nif->get(); - if (length < 0) - throw std::runtime_error("Negative NIF record list length: " + std::to_string(length)); + // No reasonable list can hit this generous limit + if (length >= (1 << 24)) + throw std::runtime_error("Record list too long: " + std::to_string(length)); - list.resize(static_cast(length)); + list.resize(length); for (auto& value : list) value.read(nif);