From e69069d53c83130d19ce54dbc4dd748e31ec3741 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 15 Mar 2018 22:01:18 -0500 Subject: [PATCH] Loading a GLB file without BIN data fails. Fixes #49. --- tiny_gltf.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 0964a53..c476a92 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -3208,7 +3208,10 @@ bool TinyGLTF::LoadBinaryFromMemory(Model *model, std::string *err, memcpy(&model_format, bytes + 16, 4); swap4(&model_format); - if ((20 + model_length >= size) || (model_length < 1) || + // In case the Bin buffer is not present, the size is exactly 20 + size of + // JSON contents, + // so use "greater than" operator. + if ((20 + model_length > size) || (model_length < 1) || (model_format != 0x4E4F534A)) { // 0x4E4F534A = JSON format. if (err) { (*err) = "Invalid glTF binary."; @@ -3739,7 +3742,8 @@ bool TinyGLTF::WriteGltfSceneToFile( json buffers; for (unsigned int i = 0; i < model->buffers.size(); ++i) { json buffer; - SerializeGltfBuffer(model->buffers[i], buffer, binSaveFilePath, binFilename); + SerializeGltfBuffer(model->buffers[i], buffer, binSaveFilePath, + binFilename); buffers.push_back(buffer); } output["buffers"] = buffers;