Fix crash in CModelInfoSA::MakeObjectModel with weapon-based objects#4951
Open
TheCrazy17 wants to merge 1 commit into
Open
Fix crash in CModelInfoSA::MakeObjectModel with weapon-based objects#4951TheCrazy17 wants to merge 1 commit into
TheCrazy17 wants to merge 1 commit into
Conversation
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.
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.
Summary
CModelInfoSA::MakeObjectModelnow allocates and copies aCClumpModelInfoSAInterface-sized buffer (instead ofCBaseModelInfoSAInterface) and resetsm_nAnimFileIndexto-1, matching the existing pattern used byMakeClumpModel.Motivation
Fixes #4241.
MakeObjectModelonly allocated and copiedsizeof(CBaseModelInfoSAInterface)bytes from the base model's interface, including its vtable pointer. When the base model is a weapon (CClumpModelInfoSAInterface-derived), the inherited vtable'sGetAnimFileIndex()readsm_nAnimFileIndexat an offset past the allocated buffer. This out-of-bounds read returns garbage, which is then used as a model ID in a recursiveCStreaming::RequestModelcall, crashing the game (e.g.engineRequestModel("object", 359)followed byengineReplaceModel).Test plan
Reproduced the crash from #4241 using
engineRequestModel("object", 359)+engineLoadTXD/engineImportTXD/engineLoadDFF/engineReplaceModelon an unpatched build. With this fix applied, the same script no longer crashes.Checklist