Fix getPedTask crash with invalid primary task index#5056
Open
HeresHavi wants to merge 1 commit into
Open
Conversation
Validate primary task indices before accessing the task array, returning no task for invalid values instead of reading out of bounds and crashing the client.
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
Added bounds validation to
CTaskManagerSA::GetTask.Primary task indices outside the valid
0to4range now returnnullptr, causinggetPedTaskto returnfalsesafely.Motivation
The primary task reader used the provided index directly on a five-entry native array. Larger values could read nearby fields and treat them as task pointers, eventually causing an access violation.
For example, a resource might loop through task slots to check what a ped is doing, but accidentally query slot
11. Instead of returningfalse, the client could interpret the ped pointer stored after the task arrays as a task and crash.Crash Stack
Test plan
Runtime
11caused an access violation inCStaticFunctionDefinitions::GetPedTask.false, and the client stayed open.3returnedfalsefor an empty valid slot.5and10returnedfalsewithout an assertion or crash.Builds and Tests
Debug | Win32: Game SA project build passed.Checklist