Skip to content

Fix getPedTask crash with invalid primary task index#5056

Open
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-getpedtask-primary-index
Open

Fix getPedTask crash with invalid primary task index#5056
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-getpedtask-primary-index

Conversation

@HeresHavi

@HeresHavi HeresHavi commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Added bounds validation to CTaskManagerSA::GetTask.

Primary task indices outside the valid 0 to 4 range now return nullptr, causing getPedTask to return false safely.

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 returning false, the client could interpret the ped pointer stored after the task arrays as a task and crash.

Crash Stack
Exception: Access violation
Module: client.dll
Module offset: 0x00107338
Requested primary task index: 11

CStaticFunctionDefinitions::GetPedTask (CStaticFunctionDefinitions.cpp:1732)
CLuaPedDefs::GetPedTask (CLuaPedDefs.cpp:555)
luaD_precall
luaV_execute
luaD_call
lua_pcall
Crash

Test plan

Runtime

  • Before Fix: Requesting primary task index 11 caused an access violation in CStaticFunctionDefinitions::GetPedTask.
  • After Fix: The same index returned false, and the client stayed open.
  • Valid Case: Primary task index 3 returned false for an empty valid slot.
  • Invalid Cases: Primary task indices 5 and 10 returned false without an assertion or crash.

Builds and Tests

  • Debug | Win32: Game SA project build passed.

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.

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.
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.

1 participant