diff --git a/tiny_gltf.h b/tiny_gltf.h index eede133..0b4a1d9 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -6147,12 +6147,19 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn, const auto bufferView = model->accessors[size_t(primitive.indices)].bufferView; - // bufferView could be null(-1) for certain extensions - if (bufferView >= 0 && bufferView < model->bufferViews.size()) { + if (bufferView < 0) { + // skip, bufferView could be null(-1) for certain extensions + } else if (size_t(bufferView) >= model->bufferViews.size()) { + if (err) { + (*err) += "accessor[" + std::to_string(primitive.indices) + + "] invalid bufferView"; + } + return false; + } else { model->bufferViews[size_t(bufferView)].target = TINYGLTF_TARGET_ELEMENT_ARRAY_BUFFER; - // we could optionally check if accessors' bufferView type is Scalar, - // as it should be + // we could optionally check if accessors' bufferView type is Scalar, as + // it should be } }