Fix out of bounds write when replacing a model with a DFF that has _dam parts - #5356
Open
Flashmyname wants to merge 1 commit into
Open
Fix out of bounds write when replacing a model with a DFF that has _dam parts#5356Flashmyname wants to merge 1 commit into
Flashmyname wants to merge 1 commit into
Conversation
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
The
_dambranch ofCFileLoader_SetRelatedModelInfoCBcasts the model info toCDamagableModelInfowithout checking.SetDamagedAtomicwrites to[this+0x20], which only exists on the damageable subclass, andCBaseModelInfoSAInterfaceis0x20bytes - so on a plain atomic model the write lands past the end of the allocation, on the next model info's vtable pointer.The game dispatches through
AsDamageAtomicModelInfoPtr(vtable slot 2) first. That call is restored, the atomic is left with the clump the caller destroys, andAtomicsReplacerskips its TXD release since nothing took a reference.Motivation
Reachable from
engineReplaceModelwith any DFF whose frame name ends in_damwhen the target model is not damageable. Slot 2 returns null for a plain atomic (0x4C4A90) andthisfor a damageable one (0x4C55C0).Test plan
A vehicle DFF onto model 2232 (plain atomic) and onto 996 (damageable, as a control), logging the dword at
modelinfo+0x20:0085BBF0is the next model info's vtable pointer. The unfixed client died on it:0xC0000005,EIP=00000000,ECX=00B154D4(the address written to),EDX=2B288E08(the value written).Checklist