Handle more edge cases while parsing OBJ;
@@ -84,6 +84,10 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source) {
char* data = (char*) source->data;
size_t length = source->size;
+ if (data[0] != '#' && !memchr(data, '\n', 1024)) {
+ return NULL;
+ }
+
vec_group_t groups;
vec_void_t textures;
vec_material_t materials;
@@ -200,6 +204,9 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source) {
}
} else {
char* newline = memchr(data, '\n', length);
+ if (!newline) {
+ break;
+ }
lineLength = newline - data + 1;
}
@@ -208,6 +215,10 @@ ModelData* lovrModelDataInitObj(ModelData* model, Blob* source) {
while (length && isspace(*data)) length--, data++;
}
+ if (vertexBlob.length == 0 || indexBlob.length == 0) {
+ return NULL;
+ }
+
model->blobCount = 2;
model->bufferCount = 2;
model->attributeCount = 3 + groups.length;
