Skip to content

Fix runtime safety and state consistency issues#5037

Open
HeresHavi wants to merge 10 commits into
multitheftauto:masterfrom
HeresHavi:runtime-safety-and-state-consistency
Open

Fix runtime safety and state consistency issues#5037
HeresHavi wants to merge 10 commits into
multitheftauto:masterfrom
HeresHavi:runtime-safety-and-state-consistency

Conversation

@HeresHavi

@HeresHavi HeresHavi commented Jul 12, 2026

Copy link
Copy Markdown

Summary

Fixed nine runtime safety and persistence issues across the client, server, and shared task scheduler.

The changes cover:

  • Input and packet validation for resource paths, resource-start names, join data, server queries, and no-cache scripts.
  • Safe shutdown and background server-cache saving.
  • Backup finalization and retrying failed account saves.

Each fix is kept in a focused commit for easier review.

Motivation

These problems mostly appeared during shutdown, malformed input, temporary database failures, filesystem errors, or background cache updates. Normal behavior could appear fine while the failure path dropped work, accepted the wrong response, or left saved data in an inconsistent state.

For example, a temporary database lock could cause an account update to be lost instead of retried. A failed backup rename could also be treated as success and allow older working backups to be removed.

Test plan

Runtime

  • Connection: Started an isolated x64 server with 206 resources, then connected, disconnected, reconnected, and shut it down normally.
  • Join Data: Confirmed the deprecated compatibility field contained exactly 32 zero bytes before a successful join.
  • Resource Paths: Rejected empty and incomplete paths on both the client and server while a valid file path still worked.
  • Resource Names: Confirmed a 255-byte exported function name worked and a 256-byte name was rejected without breaking the connection.
  • Script Packets: Confirmed a normal no-cache script transferred and executed. Truncated, zero, oversized, and mismatched lengths were rejected.
  • Server Browser: Sent a response from the wrong port before the correct response and confirmed only the requested endpoint was accepted.
  • Server Cache: Saved and reloaded 3,491 entries without invalid or duplicate endpoints.
  • Backups: Confirmed a successful backup opened normally. Forced a rename failure and confirmed older backups were preserved.
  • Accounts: Forced an asynchronous save to fail with database is locked, then confirmed it retried automatically and persisted the updated password.

Builds and Tests

  • Debug | Win32: Clean client and server component builds passed, 305 client tests passed.
  • Release | Win32: Clean client and server component builds passed, 305 client tests passed.
  • Debug | x64: Server build passed.
  • Release | x64: Server build passed.
  • Scheduler shutdown test passed 1,000 consecutive runs in both Debug and Release.
  • Ran clang-format.

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.

HeresHavi added 10 commits July 12, 2026 08:14
Ensures queued tasks finish safely when the scheduler shuts down.
Prevents empty and incomplete resource paths from causing invalid string access.
Keeps existing backups when creating or renaming a new backup fails.
Sends predictable zero-filled compatibility data instead of reading beyond an empty string.
Prevents long file and function names from corrupting resource-start packets.
Ignores server-browser replies that come from a different address or port than requested.
Rejects malformed or excessively large compressed scripts before allocating memory.
Prevents background cache saves from racing with live server-list changes.
Keeps account changes pending when the database save cannot be queued or later fails.
Finds the affected account in memory because the database may still be unavailable while handling a failed save.
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