From c577810d47a86bc3c558ff310a30c100366dcdda Mon Sep 17 00:00:00 2001 From: Max Limper Date: Sat, 1 Oct 2016 19:43:46 +0200 Subject: [PATCH] range check for vertex colors and normals in OBJ loader --- src/OpenMesh/Core/IO/reader/OBJReader.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/OpenMesh/Core/IO/reader/OBJReader.cc b/src/OpenMesh/Core/IO/reader/OBJReader.cc index 2c7036c7..3c5a3d4d 100644 --- a/src/OpenMesh/Core/IO/reader/OBJReader.cc +++ b/src/OpenMesh/Core/IO/reader/OBJReader.cc @@ -597,8 +597,14 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) // Obj counts from 1 and not zero .. array counts from zero therefore -1 vhandles.push_back(VertexHandle(value-1)); faceVertices.push_back(VertexHandle(value-1)); - if (fileOptions.vertex_has_color() ) - _bi.set_color(vhandles.back(), colors[value-1]); + if (fileOptions.vertex_has_color()) { + if ((unsigned int)(value - 1) < colors.size()) { + _bi.set_color(vhandles.back(), colors[value - 1]); + } + else { + omerr() << "Error setting vertex color" << std::endl; + } + } break; case 1: // texture coord @@ -648,9 +654,13 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt) // Obj counts from 1 and not zero .. array counts from zero therefore -1 if (fileOptions.vertex_has_normal() ) { - assert(!vhandles.empty()); - assert((unsigned int)(value-1) < normals.size()); - _bi.set_normal(vhandles.back(), normals[value-1]); + assert(!vhandles.empty()); + if ((unsigned int)(value - 1) < normals.size()) { + _bi.set_normal(vhandles.back(), normals[value - 1]); + } + else { + omerr() << "Error setting vertex normal" << std::endl; + } } break; } -- GitLab