Skip to content

Commit 7e7830e

Browse files
Validate glTF data in CgltfLoader (#2975)
This changelist adds a `cgltf_validate` step to `CgltfLoader`, rejecting invalid glTF files before their contents are used to construct meshes. The cgltf parser is intentionally permissive, and does not verify that accessor ranges, buffer view extents, and object references are internally consistent. Validating the parsed data after buffer loading guards downstream mesh construction code against out-of-bounds reads when an invalid asset is loaded. This changelist additionally fixes a memory leak in `CgltfLoader`, where a failure in buffer loading or validation would previously return without freeing the data allocated by `cgltf_parse_file`.
1 parent ccaf607 commit 7e7830e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

source/MaterialXRender/CgltfLoader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ bool CgltfLoader::load(const FilePath& filePath, MeshList& meshList, bool texcoo
149149
{
150150
return false;
151151
}
152-
if (cgltf_load_buffers(&options, data, input_filename.c_str()) != cgltf_result_success)
152+
if (cgltf_load_buffers(&options, data, input_filename.c_str()) != cgltf_result_success ||
153+
cgltf_validate(data) != cgltf_result_success)
153154
{
155+
cgltf_free(data);
154156
return false;
155157
}
156158

0 commit comments

Comments
 (0)