Commit 29ba85a7 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'OBJ-loader-check-ranges' into 'master'

range check for vertex colors and normals in OBJ loader

This merge request adds explicit range checks and error reporting for the reading of colors and normals. The code is copied from texture coordinates, where a similar check already existed.

See merge request !92
parents d606073a c577810d
Pipeline #2977 passed with stage
in 30 minutes and 54 seconds
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment