Skip to content

Fix client crash from invalid sound FFT band counts#5048

Open
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-sound-fft-band-count-crash
Open

Fix client crash from invalid sound FFT band counts#5048
HeresHavi wants to merge 1 commit into
multitheftauto:masterfrom
HeresHavi:fix-sound-fft-band-count-crash

Conversation

@HeresHavi

@HeresHavi HeresHavi commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Added FFT band-count validation for sound elements and player voice.

Band counts from zero through half the requested FFT sample count remain valid. Negative values and values above the available half-spectrum now return false before FFT extraction or allocation.

Motivation

getSoundFFTData accepted any signed band count. A value of -1 reached new float[iBands] and became an extremely large allocation request, causing MTA's out-of-memory handler to terminate the client.

For example, a resource might use FFT data to draw a music visualizer and allow the number of bands to come from a setting. If that value becomes negative or exceeds the available spectrum, the old code could terminate the player's client or read beyond the FFT data.

The reported out-of-memory error was caused by the invalid allocation size. The machine had not actually run out of memory.

Crash Stack
RaiseException
OutOfMemory
HandleMemoryAllocationFailure
_callnewh
operator new
CStaticFunctionDefinitions::GetSoundFFTData
CLuaAudioDefs::GetSoundFFTData
luaD_precall
luaV_execute
luaD_call
lua_pcall
CLuaMain::PCall
Crash Out of memory dialog

Test plan

Runtime

  • Valid Case: A 256-sample FFT with 16 bands returned a table containing 16 entries before and after the fix.
  • Before Fix: Requesting bands = -1 terminated the client through the out-of-memory handler.
  • After Fix: The same negative band count returned false, and the client stayed open.
  • Maximum Case: bands = 128 returned a table containing 128 entries.
  • Boundary Case: bands = 129 returned false, and the client stayed open.

Builds and Tests

  • Debug | Win32: Full build passed, 304 client tests passed.
  • Release | Win32: Full build passed, 304 client tests passed.
  • Debug | x64: Full build passed.
  • Release | x64: Full build passed.
  • 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.

Validate FFT band counts before extracting or allocating spectrum data to prevent negative and oversized values from crashing the client or reading beyond the available FFT data.
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