From 9471517c1eb68ab4120aa933e0d573bf81584278 Mon Sep 17 00:00:00 2001 From: Jack Mousseau Date: Thu, 24 Feb 2022 14:25:37 -0800 Subject: [PATCH 1/2] Fix byte offset optionality for sparse accessor indices and values --- tiny_gltf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index 821f2b5..d0445e6 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -4238,7 +4238,7 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, ParseIntegerProperty(&indices_buffer_view, err, indices_obj, "bufferView", true); ParseIntegerProperty(&indices_byte_offset, err, indices_obj, "byteOffset", - true); + false); ParseIntegerProperty(&component_type, err, indices_obj, "componentType", true); @@ -4246,7 +4246,7 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView", true); ParseIntegerProperty(&values_byte_offset, err, values_obj, "byteOffset", - true); + false); accessor->sparse.count = count; accessor->sparse.indices.bufferView = indices_buffer_view; From cbd38850493318560bf21195261356af94af510e Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 26 Feb 2022 21:19:15 +0900 Subject: [PATCH 2/2] Check required attribute exists for SparseAccessor. --- tiny_gltf.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tiny_gltf.h b/tiny_gltf.h index d0445e6..ba44e65 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -2217,7 +2217,7 @@ std::string base64_decode(std::string const &encoded_string) { // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// +// namespace dlib { inline unsigned char from_hex(unsigned char ch) { @@ -4217,7 +4217,9 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, accessor->sparse.isSparse = true; int count = 0; - ParseIntegerProperty(&count, err, o, "count", true); + if (!ParseIntegerProperty(&count, err, o, "count", true, "SparseAccessor")) { + return false; + } json_const_iterator indices_iterator; json_const_iterator values_iterator; @@ -4235,16 +4237,22 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, const json &values_obj = GetValue(values_iterator); int indices_buffer_view = 0, indices_byte_offset = 0, component_type = 0; - ParseIntegerProperty(&indices_buffer_view, err, indices_obj, "bufferView", - true); + if (!ParseIntegerProperty(&indices_buffer_view, err, indices_obj, "bufferView", + true, "SparseAccessor")) { + return false; + } ParseIntegerProperty(&indices_byte_offset, err, indices_obj, "byteOffset", false); - ParseIntegerProperty(&component_type, err, indices_obj, "componentType", - true); + if (!ParseIntegerProperty(&component_type, err, indices_obj, "componentType", + true, "SparseAccessor")) { + return false; + } int values_buffer_view = 0, values_byte_offset = 0; - ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView", - true); + if (!ParseIntegerProperty(&values_buffer_view, err, values_obj, "bufferView", + true, "SparseAccessor")) { + return false; + } ParseIntegerProperty(&values_byte_offset, err, values_obj, "byteOffset", false); @@ -4255,8 +4263,6 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err, accessor->sparse.values.bufferView = values_buffer_view; accessor->sparse.values.byteOffset = values_byte_offset; - // todo check theses values - return true; }