Fix out of bounds access to rotation array in assimp loader #479
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🦟 Bug fix
Alternative to #478, it fixes the root cause of the issue that is undefined behavior due to access past the end of the array.
Summary
When the parsing function was written, the assumption was that the position keys array and the rotation keys array would be the same length, this proved to not be the case since they can have different lengths.
The root cause of the issue addressed through #478 was that the rotation key array only had one element while the position key array was much longer, hence we were accessing values past the end of the array which is undefined behavior and can cause all sorts of trouble to downstream users.
Other cases with other animations can cause NaN exceptions in OGRE2 that crash the whole application.
With this PR we iterate over the longest of the arrays (to make sure no data is lost) and set the access to the position / rotation keys to be the minimum between the current index and the length of the array, to avoid undefined behavior.
This means that the last key will be duplicated in case the array is shorter, but that is acceptable behavior. It seems assimp returns a rotation array of length 1 to denote that rotation does not change throughout the animation.
The first one-line commit fixes the issue we are personally observing but I added f2cb2ce to fix the symmetrical case
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.