fix: avoid out-of-bounds array access in modelinfomgr#230
Open
CanerKaraca23 wants to merge 2 commits intouser-grinch:mainfrom
Open
fix: avoid out-of-bounds array access in modelinfomgr#230CanerKaraca23 wants to merge 2 commits intouser-grinch:mainfrom
CanerKaraca23 wants to merge 2 commits intouser-grinch:mainfrom
Conversation
Removes a hacky frame count check previously used to avoid a crash when processing SirenLight materials. Replaces it with proper bounds checking for indices returned by GetSirenIndex and GetStrobeIndex before accessing the associated status arrays.
Removes a hacky frame count check previously used to avoid a crash when processing SirenLight materials. Replaces it with proper bounds checking for indices returned by GetSirenIndex and GetStrobeIndex before accessing the associated status arrays.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ModelInfoMgr::SetEditableMaterialsCB against out-of-bounds reads when resolving siren/strobe material states by validating indices returned from GetSirenIndex / GetStrobeIndex, removing the prior frame-count-based workaround.
Changes:
- Removed the early-return “frame count <= 10” workaround for siren materials.
- Added explicit bounds checks before reading
m_SirenStatus[]andm_StrobeStatus[]using the computed indices.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
238
to
242
| eMaterialType iLightIndex = FetchMaterialType(pCurVeh, material); | ||
| if (iLightIndex != eMaterialType::UnknownMaterial) | ||
| { | ||
| auto &data = m_VehData.Get(pCurVeh); | ||
|
|
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.
🎯 What: Removed a hacky
data.nFrameCount <= 10check used to workaround a crash and replaced it with strict bounds checking before accessingm_SirenStatusandm_StrobeStatusarrays based onGetSirenIndex/GetStrobeIndex.💡 Why: The frame count check delayed the bug but didn't actually fix the root cause, which was out-of-bounds array reads. Checking the index ensures memory safety regardless of the frame counter, which is cleaner and less susceptible to race conditions.
✅ Verification: Verified by a code reviewer confirming the logical correctness of checking array limits
idx >= 0 && idx < MAX_LIGHTSbefore proceeding with the read. Avoided polluting the repo withcompile_commands.jsonorplugin-sdkdownloads.✨ Result: Improved crash resilience and robustness for vehicle material rendering without arbitrary frame delay workarounds.