From e1fd58c508b77b0e339adf185addc8f63763a595 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 17 Mar 2020 03:22:42 -0400
Subject: [PATCH] Prevent invalid array access during loadModel

---
 indra/llprimitive/llmodel.cpp | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp
index 37548e3fe34..98a0e902ecc 100644
--- a/indra/llprimitive/llmodel.cpp
+++ b/indra/llprimitive/llmodel.cpp
@@ -1115,19 +1115,16 @@ bool LLModel::loadModel(std::istream& is)
 	}
 
 	mSubmodelID = header.has("submodel_id") ? header["submodel_id"].asInteger() : false;
-
-	static const std::string lod_name[] = 
-	{
-		"lowest_lod",
-		"low_lod",
-		"medium_lod",
-		"high_lod",
-		"physics_mesh",
-	};
-
-	const S32 MODEL_LODS = 5;
-
-	S32 lod = llclamp((S32) mDetail, 0, MODEL_LODS);
+    
+    static const std::array<std::string, 5> lod_name = {{
+        "lowest_lod",
+        "low_lod",
+        "medium_lod",
+        "high_lod",
+        "physics_mesh",
+    }};
+
+	S32 lod = llclamp(static_cast<S32>(mDetail), 0, static_cast<S32>(lod_name.size()) - 1);
 
 	if (header[lod_name[lod]]["offset"].asInteger() == -1 || 
 		header[lod_name[lod]]["size"].asInteger() == 0 )
-- 
GitLab