Merge pull request #512 from ctrlaltf2/oob-fix

Add bounds check to images loaded from bufferviews
This commit is contained in:
Syoyo Fujita 2025-01-22 22:45:07 +09:00 committed by GitHub
commit a5e653e46c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6453,6 +6453,15 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
return false; return false;
} }
const Buffer &buffer = model->buffers[size_t(bufferView.buffer)]; const Buffer &buffer = model->buffers[size_t(bufferView.buffer)];
if (bufferView.byteOffset >= buffer.data.size()) {
if (err) {
std::stringstream ss;
ss << "image[" << idx << "] bufferView \"" << image.bufferView
<< "\" indexed out of bounds of its buffer." << std::endl;
(*err) += ss.str();
}
return false;
}
if (LoadImageData == nullptr) { if (LoadImageData == nullptr) {
if (err) { if (err) {