Check input vertex coordinates for NaNs when loading STL meshes.
PiperOrigin-RevId: 465327574 Change-Id: I985170941d217031c169ee5107dd1a3bcd27b6af
This commit is contained in:
committed by
Copybara-Service
parent
3a3ca37615
commit
999c345b93
+18
-10
@@ -623,7 +623,6 @@ void mjCMesh::LoadOBJ(const mjVFS* vfs) {
|
|||||||
// load STL binary mesh
|
// load STL binary mesh
|
||||||
void mjCMesh::LoadSTL(const mjVFS* vfs) {
|
void mjCMesh::LoadSTL(const mjVFS* vfs) {
|
||||||
bool righthand = (scale[0]*scale[1]*scale[2]>0);
|
bool righthand = (scale[0]*scale[1]*scale[2]>0);
|
||||||
int i, j;
|
|
||||||
|
|
||||||
// make filename
|
// make filename
|
||||||
string filename = mjuu_makefullname(model->modelfiledir, model->meshdir, file);
|
string filename = mjuu_makefullname(model->modelfiledir, model->meshdir, file);
|
||||||
@@ -690,20 +689,29 @@ void mjCMesh::LoadSTL(const mjVFS* vfs) {
|
|||||||
vert = (float*) mju_malloc(9*nface*sizeof(float));
|
vert = (float*) mju_malloc(9*nface*sizeof(float));
|
||||||
|
|
||||||
// add vertices and faces, including repeated for now
|
// add vertices and faces, including repeated for now
|
||||||
for (i=0; i<nface; i++) {
|
for (int i=0; i<nface; i++) {
|
||||||
for (j=0; j<3; j++) {
|
for (int j=0; j<3; j++) {
|
||||||
// get pointer to vertex coordiates
|
// get pointer to vertex coordiates
|
||||||
float* v = (float*)(stl+50*i+12*(j+1));
|
float* v = (float*)(stl+50*i+12*(j+1));
|
||||||
|
for (int k=0; k < 3; k++) {
|
||||||
|
if (std::isnan(v[k]) || std::isinf(v[k])) {
|
||||||
|
if (!flag_existing) {
|
||||||
|
mju_free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
// check if vertex coordinates can be cast to an int safely
|
throw mjCError(this, "STL file '%s' contains invalid vertices.",
|
||||||
if (fabs(v[0])>pow(2, 30) || fabs(v[1])>pow(2, 30) || fabs(v[2])>pow(2, 30)) {
|
filename.c_str());
|
||||||
if (!flag_existing) {
|
|
||||||
mju_free(buffer);
|
|
||||||
}
|
}
|
||||||
|
// check if vertex coordinates can be cast to an int safely
|
||||||
|
if (fabs(v[k])>pow(2, 30)) {
|
||||||
|
if (!flag_existing) {
|
||||||
|
mju_free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
throw mjCError(this,
|
throw mjCError(this,
|
||||||
"vertex coordinates in STL file '%s' exceed maximum bounds",
|
"vertex coordinates in STL file '%s' exceed maximum bounds",
|
||||||
filename.c_str());
|
filename.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add vertex address in face; change order if scale makes it lefthanded
|
// add vertex address in face; change order if scale makes it lefthanded
|
||||||
|
|||||||
Reference in New Issue
Block a user