Skip to content

fix: avoid out-of-bounds array access in modelinfomgr#230

Open
CanerKaraca23 wants to merge 2 commits intouser-grinch:mainfrom
CanerKaraca23:fix-modelinfomgr-bounds-check-2942288192757790142
Open

fix: avoid out-of-bounds array access in modelinfomgr#230
CanerKaraca23 wants to merge 2 commits intouser-grinch:mainfrom
CanerKaraca23:fix-modelinfomgr-bounds-check-2942288192757790142

Conversation

@CanerKaraca23
Copy link
Copy Markdown
Contributor

🎯 What: Removed a hacky data.nFrameCount <= 10 check used to workaround a crash and replaced it with strict bounds checking before accessing m_SirenStatus and m_StrobeStatus arrays based on GetSirenIndex / 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_LIGHTS before proceeding with the read. Avoided polluting the repo with compile_commands.json or plugin-sdk downloads.

Result: Improved crash resilience and robustness for vehicle material rendering without arbitrary frame delay workarounds.

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.
Copilot AI review requested due to automatic review settings May 8, 2026 19:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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[] and m_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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants