From 28436557b1e9a1836290bdb5ba00f7da677ff535 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 5 Aug 2023 03:19:36 +0200 Subject: [PATCH] Validate fillVertexBuffers arguments --- components/esm3terrain/storage.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/esm3terrain/storage.cpp b/components/esm3terrain/storage.cpp index cb2b8904f7..408b059774 100644 --- a/components/esm3terrain/storage.cpp +++ b/components/esm3terrain/storage.cpp @@ -1,6 +1,7 @@ #include "storage.hpp" #include +#include #include #include @@ -186,6 +187,12 @@ namespace ESMTerrain void Storage::fillVertexBuffers(int lodLevel, float size, const osg::Vec2f& center, ESM::RefId worldspace, osg::Vec3Array& positions, osg::Vec3Array& normals, osg::Vec4ubArray& colours) { + if (lodLevel < 0 || 63 < lodLevel) + throw std::invalid_argument("Invalid terrain lod level: " + std::to_string(lodLevel)); + + if (size <= 0) + throw std::invalid_argument("Invalid terrain size: " + std::to_string(size)); + // LOD level n means every 2^n-th vertex is kept const std::size_t sampleSize = std::size_t{ 1 } << lodLevel;