diff --git a/code/AssetLib/glTF/glTFAsset.inl b/code/AssetLib/glTF/glTFAsset.inl index 896a9f16c..10be7c78e 100644 --- a/code/AssetLib/glTF/glTFAsset.inl +++ b/code/AssetLib/glTF/glTFAsset.inl @@ -1147,6 +1147,7 @@ inline void Asset::ReadBinaryHeader(IOStream &stream) { AI_SWAP4(header.length); AI_SWAP4(header.sceneLength); + static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "size_t must be at least 32bits"); mSceneLength = static_cast(header.sceneLength); // Can't be larger than 4GB (max. uint32_t) mBodyOffset = sizeof(header) + mSceneLength; @@ -1184,7 +1185,7 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) { } // Binary format only supports up to 4GB of JSON so limit it there to avoid extreme memory allocation - if (mSceneLength > std::numeric_limits::max()) { + if (mSceneLength >= std::numeric_limits::max()) { throw DeadlyImportError("GLTF: JSON size greater than 4GB"); } diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 479749523..3fc238208 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -1777,7 +1777,7 @@ inline void Asset::ReadBinaryHeader(IOStream &stream, std::vector &sceneDa } // read the scene data, ensure null termination - + static_assert(std::numeric_limits::max() <= std::numeric_limits::max(), "size_t must be at least 32bits"); mSceneLength = chunk.chunkLength; // Can't be larger than 4GB (max. uint32_t) sceneData.resize(mSceneLength + 1); sceneData[mSceneLength] = '\0'; @@ -1836,7 +1836,7 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) { mBodyLength = 0; // Binary format only supports up to 4GB of JSON, use that as a maximum - if (mSceneLength > std::numeric_limits::max()) { + if (mSceneLength >= std::numeric_limits::max()) { throw DeadlyImportError("GLTF: JSON size greater than 4GB"); }