Skip to content

Fix crash in CModelInfoSA::MakeObjectModel with weapon-based objects#4951

Open
TheCrazy17 wants to merge 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix/makeobjectmodel-weapon-oob
Open

Fix crash in CModelInfoSA::MakeObjectModel with weapon-based objects#4951
TheCrazy17 wants to merge 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix/makeobjectmodel-weapon-oob

Conversation

@TheCrazy17

Copy link
Copy Markdown

Summary

CModelInfoSA::MakeObjectModel now allocates and copies a CClumpModelInfoSAInterface-sized buffer (instead of CBaseModelInfoSAInterface) and resets m_nAnimFileIndex to -1, matching the existing pattern used by MakeClumpModel.

Motivation

Fixes #4241.

MakeObjectModel only allocated and copied sizeof(CBaseModelInfoSAInterface) bytes from the base model's interface, including its vtable pointer. When the base model is a weapon (CClumpModelInfoSAInterface-derived), the inherited vtable's GetAnimFileIndex() reads m_nAnimFileIndex at an offset past the allocated buffer. This out-of-bounds read returns garbage, which is then used as a model ID in a recursive CStreaming::RequestModel call, crashing the game (e.g. engineRequestModel("object", 359) followed by engineReplaceModel).

Test plan

Reproduced the crash from #4241 using engineRequestModel("object", 359) + engineLoadTXD/engineImportTXD/engineLoadDFF/engineReplaceModel on an unpatched build. With this fix applied, the same script no longer crashes.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

MakeObjectModel copied only sizeof(CBaseModelInfoSAInterface) bytes,
including the base model's vtable pointer. For weapon models, the
inherited GetAnimFileIndex() reads m_nAnimFileIndex past the allocated
buffer, returning garbage used as a model ID and crashing the game.

Allocate/copy a CClumpModelInfoSAInterface instead, like MakeClumpModel
does, and reset m_nAnimFileIndex to -1.
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.

Using a weapon model id for engineRequestModel and then replacing it crashes the game (0x00004C95)

1 participant