mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-07-04 18:05:11 +08:00
Fix possible out of bounds index in LoadFromString
This commit is contained in:
parent
4581d37bec
commit
e413216722
27
tiny_gltf.h
27
tiny_gltf.h
@ -5803,20 +5803,27 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
|
||||
}
|
||||
|
||||
for (auto &attribute : primitive.attributes) {
|
||||
model
|
||||
->bufferViews[size_t(
|
||||
model->accessors[size_t(attribute.second)].bufferView)]
|
||||
.target = TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||
const auto accessorsIndex = size_t(attribute.second);
|
||||
if (accessorsIndex < model->accessors.size()) {
|
||||
const auto bufferView = model->accessors[accessorsIndex].bufferView;
|
||||
// bufferView could be null(-1) for sparse morph target
|
||||
if (bufferView >= 0 && bufferView < model->bufferViews.size()) {
|
||||
model->bufferViews[size_t(bufferView)].target =
|
||||
TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &target : primitive.targets) {
|
||||
for (auto &attribute : target) {
|
||||
auto bufferView =
|
||||
model->accessors[size_t(attribute.second)].bufferView;
|
||||
// bufferView could be null(-1) for sparse morph target
|
||||
if (bufferView >= 0) {
|
||||
model->bufferViews[size_t(bufferView)].target =
|
||||
TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||
const auto accessorsIndex = size_t(attribute.second);
|
||||
if (accessorsIndex < model->accessors.size()) {
|
||||
const auto bufferView = model->accessors[accessorsIndex].bufferView;
|
||||
// bufferView could be null(-1) for sparse morph target
|
||||
if (bufferView >= 0 && bufferView < model->bufferViews.size()) {
|
||||
model->bufferViews[size_t(bufferView)].target =
|
||||
TINYGLTF_TARGET_ARRAY_BUFFER;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user