From ddb74c2bbdee1565dda667e85f0c82a0588c8053 Mon Sep 17 00:00:00 2001
From: Kim Kulling <kimkulling@users.noreply.github.com>
Date: Wed, 3 Jul 2024 21:37:24 +0200
Subject: [PATCH] Fix out of bound access (#5651)

---
 code/AssetLib/Ply/PlyLoader.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/code/AssetLib/Ply/PlyLoader.cpp b/code/AssetLib/Ply/PlyLoader.cpp
index 783c7f1..e109541 100644
--- a/code/AssetLib/Ply/PlyLoader.cpp
+++ b/code/AssetLib/Ply/PlyLoader.cpp
@@ -567,6 +567,10 @@ void PLYImporter::LoadFace(const PLY::Element *pcElement, const PLY::ElementInst
         if (mGeneratedMesh->mFaces == nullptr) {
             mGeneratedMesh->mNumFaces = pcElement->NumOccur;
             mGeneratedMesh->mFaces = new aiFace[mGeneratedMesh->mNumFaces];
+        } else {
+            if (mGeneratedMesh->mNumFaces < pcElement->NumOccur) {
+                throw DeadlyImportError("Invalid .ply file: Too many faces");
+            }
         }
 
         if (!bIsTriStrip) {
-- 
2.41.0

