Repository navigation
[rmodels] Fix LoadOBJ() reading past vertex data on out-of-range face indices - #6199
Merged
Merged
Conversation
… indices Face indices come straight from the file. Positions were read without any bounds check, and texcoord/normal indices were only checked for >= 0, so a face referencing a missing vertex, texcoord or normal (or a relative index that resolves below zero) read outside the attribute arrays. Skip out-of-range indices, keeping the zeroed position and texcoord and the default normal, as already done for missing texcoords and normals.
Owner
|
@antonsoo thanks for the review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
LoadOBJ()copies positions, texcoords and normals using the face indices from the file. Positions were not bounds-checked at all, and texcoord/normal indices were only checked for>= 0, so a face that references a vertex, texcoord or normal the file doesn't have reads outside the attribute arrays. A 4-line file is enough:(
f 1/1/1 2/5/1 3/1/1with onevt,f 1/1/1 2/1/7 3/1/1with onevn, and a relative index such asf -1 -2 -5do the same for texcoords, normals and negative indices.)Out-of-range indices are now skipped: the position and texcoord stay zero and the normal gets the existing default, as the loader already does for missing texcoords/normals.
Tested with AddressSanitizer: the malformed files above no longer read out of bounds, and all 12 OBJ models in
examples/models/resourcesload to byte-identical vertex data before and after the change.