Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash from importing a certain kind of invalid GLTF #83663

Merged

Conversation

jsjtxietian
Copy link
Contributor

Invalid type: mistach interpolation CUBICSPLINE and value size. Might need to change the description and maybe more protections are needed.

Fixes #83617

invalid type: mistach interpolation CUBICSPLINE and value size
@jsjtxietian jsjtxietian requested a review from a team as a code owner October 20, 2023 09:01
@akien-mga akien-mga added this to the 4.2 milestone Oct 20, 2023
Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not at a computer but the code moves the ternary operator outside indexing operator and adds a check for error. Checked the pattern seems ok but haven’t tested with data. The cubic gltf interpolation is a bit rare and need to check a test case.

Will cause error spam on for example thousands of animation tracks. try printing once

@@ -6224,7 +6224,9 @@ void GLTFDocument::_import_animation(Ref<GLTFState> 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int value_index = 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;

For readability, same below

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, was preparing a batch of approved PRs and I missed this comment.

@akien-mga akien-mga merged commit 78e47a4 into godotengine:master Oct 20, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@jsjtxietian jsjtxietian deleted the prevent-invalid-gltf-crash-godot branch October 20, 2023 14:19
@jsjtxietian jsjtxietian restored the prevent-invalid-gltf-crash-godot branch October 20, 2023 14:19
@jsjtxietian jsjtxietian deleted the prevent-invalid-gltf-crash-godot branch October 20, 2023 14:23
@akien-mga akien-mga changed the title Prevent godot crash from importing a certain kind of invalid gltf Prevent crash from importing a certain kind of invalid GLTF Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

This invalid glTF file crashes Godot
4 participants