-
Notifications
You must be signed in to change notification settings - Fork 436
Fix heap buffer overflow for high valence subdivision vertices #632
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
Open
stefanatwork
wants to merge
2
commits into
master
Choose a base branch
from
fix/subdiv-ring-valence-overflow
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−5
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ namespace embree | |
|
|
||
| HalfEdge () | ||
| : vtx_index(-1), next_half_edge_ofs(0), prev_half_edge_ofs(0), opposite_half_edge_ofs(0), edge_crease_weight(0), | ||
| vertex_crease_weight(0), edge_level(0), patch_type(COMPLEX_PATCH), vertex_type(REGULAR_VERTEX) | ||
| vertex_crease_weight(0), edge_level(0), patch_type(COMPLEX_PATCH), vertex_type(REGULAR_VERTEX), valid_patch(false) | ||
| { | ||
| static_assert(sizeof(HalfEdge) == 32, "invalid half edge size"); | ||
| } | ||
|
|
@@ -354,6 +354,62 @@ namespace embree | |
|
|
||
| return faceValence <= MAX_RING_FACE_VALENCE && edgeValence <= MAX_RING_EDGE_VALENCE; | ||
| } | ||
|
|
||
| /*! tests if the ring around the start vertex is within the supported size | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not need that function, one can just use topo->valid() ? |
||
| * limits. In contrast to validRing this test only depends on the topology | ||
| * and not on the vertex positions. */ | ||
| __forceinline bool validRingTopology() const | ||
| { | ||
| size_t faceValence = 0; | ||
| size_t edgeValence = 0; | ||
|
|
||
| const HalfEdge* p = this; | ||
| do | ||
| { | ||
| /* check size of current face */ | ||
| const size_t n = p->numEdges(); | ||
| if (n < 3 || n > MAX_PATCH_VALENCE) | ||
| return false; | ||
| edgeValence += n-2; | ||
|
|
||
| faceValence++; | ||
| p = p->prev(); | ||
|
|
||
| /* continue with next face */ | ||
| if (likely(p->hasOpposite())) | ||
| p = p->opposite(); | ||
|
|
||
| /* if there is no opposite go the long way to the other side of the border */ | ||
| else { | ||
| faceValence++; | ||
| edgeValence++; | ||
| p = this; | ||
| while (p->hasOpposite()) | ||
| p = p->opposite()->next(); | ||
| } | ||
|
|
||
| /* stop early for degenerated topology */ | ||
| if (faceValence > MAX_RING_FACE_VALENCE || edgeValence > MAX_RING_EDGE_VALENCE) | ||
| return false; | ||
|
|
||
| } while (p != this); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public: | ||
|
|
||
| /*! tests if this patch and all its rings are within the supported size | ||
| * limits. Patches that are not, cannot get evaluated. */ | ||
| __forceinline bool validPatchTopology() const | ||
| { | ||
| size_t N = 1; | ||
| if (!this->validRingTopology()) return false; | ||
| for (const HalfEdge* p=this->next(); p!=this; p=p->next(), N++) { | ||
| if (!p->validRingTopology()) return false; | ||
| } | ||
| return N >= 3 && N <= MAX_PATCH_VALENCE; | ||
| } | ||
|
|
||
| private: | ||
| unsigned int vtx_index; //!< index of edge start vertex | ||
|
|
@@ -367,6 +423,7 @@ namespace embree | |
| float edge_level; //!< subdivision factor for edge | ||
| PatchType patch_type; //!< stores type of subdiv patch | ||
| VertexType vertex_type; //!< stores type of the start vertex | ||
| char align[2]; | ||
| bool valid_patch; //!< stores if the patch can be evaluated | ||
| char align[1]; | ||
| }; | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here should just be topo->valid(primID)? This->valid() uses the main topology which is for geometry. But even if that is invalid, if the attribute topology is still ok all is fine.