diff --git a/src/libslic3r/Format/OBJ.cpp b/src/libslic3r/Format/OBJ.cpp index aa389781af..f0a002f50d 100644 --- a/src/libslic3r/Format/OBJ.cpp +++ b/src/libslic3r/Format/OBJ.cpp @@ -70,7 +70,8 @@ bool load_obj(const char *path, TriangleMesh *meshptr) ++ num_normals; } } - if (data.vertices[i].coordIdx != -1) { + // Result of obj_parseline() call is not checked, thus not all vertices are necessarily finalized with coord_Idx == -1. + if (i < data.vertices.size() && data.vertices[i].coordIdx != -1) { // This is a quad. Produce the other triangle. stl_facet &facet2 = stl.facet_start[i_face++]; facet2.vertex[0] = facet.vertex[0]; diff --git a/src/libslic3r/Format/objparser.cpp b/src/libslic3r/Format/objparser.cpp index 8c1a53459d..f675bfd66e 100644 --- a/src/libslic3r/Format/objparser.cpp +++ b/src/libslic3r/Format/objparser.cpp @@ -338,11 +338,14 @@ bool objparse(const char *path, ObjData &data) char *c = buf + lastLine; while (*c == ' ' || *c == '\t') ++ c; + //FIXME check the return value and exit on error? + // Will it break parsing of some obj files? obj_parseline(c, data); lastLine = i + 1; } lenPrev = len - lastLine; memmove(buf, buf + lastLine, lenPrev); + assert(lenPrev <= 65536); } } catch (std::bad_alloc&) {