Fix out-of-bounds write in point query instance stack - #630
Open
stefanatwork wants to merge 1 commit into
Open
stefanatwork wants to merge 1 commit into
stefanatwork wants to merge 1 commit into
Conversation
The point query variant of instance_id_stack::push() guarded the instance stack capacity only with an assert, which is compiled out in release builds. It then unconditionally wrote the instance ID and both 4x4 transform matrices at context->instStackSize and always returned true. Since rtcPointQuery() recurses into nested instances and all call sites gate recursion on the return value of push(), the missing runtime check meant a scene nested deeper than RTC_MAX_INSTANCE_LEVEL_COUNT drove instStackSize past the fixed-size arrays of the caller provided RTCPointQueryContext, writing instance transform data out of bounds. With the default RTC_MAX_INSTANCE_LEVEL_COUNT of 1, an instance of an instance is enough to corrupt memory past the context; deeper nesting scales the write distance arbitrarily. Add the same runtime capacity check that the intersect/occluded variant of push() already performs: return false before any write when the stack is full. This makes point queries silently ignore instances nested deeper than RTC_MAX_INSTANCE_LEVEL_COUNT, which is the behaviour already documented for instancing and already implemented for ray queries. The existing call sites handle a false return by skipping the instance without a matching pop(), so the stack stays balanced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
svenwoop
approved these changes
Sep 23, 2026
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.
The point query variant of instance_id_stack::push() guarded the instance stack capacity only with an assert, which is compiled out in release builds. It then unconditionally wrote the instance ID and both 4x4 transform matrices at context->instStackSize and always returned true.
Since rtcPointQuery() recurses into nested instances and all call sites gate recursion on the return value of push(), the missing runtime check meant a scene nested deeper than RTC_MAX_INSTANCE_LEVEL_COUNT drove instStackSize past the fixed-size arrays of the caller provided RTCPointQueryContext, writing instance transform data out of bounds. With the default RTC_MAX_INSTANCE_LEVEL_COUNT of 1, an instance of an instance is enough to corrupt memory past the context; deeper nesting scales the write distance arbitrarily.
Add the same runtime capacity check that the intersect/occluded variant of push() already performs: return false before any write when the stack is full. This makes point queries silently ignore instances nested deeper than RTC_MAX_INSTANCE_LEVEL_COUNT, which is the behaviour already documented for instancing and already implemented for ray queries. The existing call sites handle a false return by skipping the instance without a matching pop(), so the stack stays balanced.