From 1c70a7ae6a3286c588cdd7117096d67149925b2a Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Fri, 20 Oct 2023 16:56:49 +0800 Subject: [PATCH] Prevent godot crash from importing a certain kind of invalid gltf invalid type: mistach interpolation CUBICSPLINE and value size --- modules/gltf/gltf_document.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 324eb79ea2..47fc58fe43 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -6224,7 +6224,9 @@ void GLTFDocument::_import_animation(Ref p_state, AnimationPlayer *p_ if (p_remove_immutable_tracks) { Vector3 base_pos = p_state->nodes[track_i.key]->position; for (int i = 0; i < track.position_track.times.size(); i++) { - Vector3 value = track.position_track.values[track.position_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i]; + int value_index = track.position_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; + ERR_FAIL_COND_MSG(value_index >= track.position_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); + Vector3 value = track.position_track.values[value_index]; if (!value.is_equal_approx(base_pos)) { is_default = false; break; @@ -6244,7 +6246,9 @@ void GLTFDocument::_import_animation(Ref p_state, AnimationPlayer *p_ if (p_remove_immutable_tracks) { Quaternion base_rot = p_state->nodes[track_i.key]->rotation.normalized(); for (int i = 0; i < track.rotation_track.times.size(); i++) { - Quaternion value = track.rotation_track.values[track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i].normalized(); + int value_index = track.rotation_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; + ERR_FAIL_COND_MSG(value_index >= track.rotation_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); + Quaternion value = track.rotation_track.values[value_index].normalized(); if (!value.is_equal_approx(base_rot)) { is_default = false; break; @@ -6264,7 +6268,9 @@ void GLTFDocument::_import_animation(Ref p_state, AnimationPlayer *p_ if (p_remove_immutable_tracks) { Vector3 base_scale = p_state->nodes[track_i.key]->scale; for (int i = 0; i < track.scale_track.times.size(); i++) { - Vector3 value = track.scale_track.values[track.scale_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i]; + int value_index = track.scale_track.interpolation == GLTFAnimation::INTERP_CUBIC_SPLINE ? (1 + i * 3) : i; + ERR_FAIL_COND_MSG(value_index >= track.scale_track.values.size(), "Animation sampler output accessor with 'CUBICSPLINE' interpolation doesn't have enough elements."); + Vector3 value = track.scale_track.values[value_index]; if (!value.is_equal_approx(base_scale)) { is_default = false; break;