Avoid division by 0 when parsing WAV data
Don't divide by waveformat.uiBlockAlign which could be 0, but rather multiply by it and verify that we get the expected result. This is more robust, as it prevents crashes on malformed input and also slightly more efficient even for correct input.
This commit is contained in:
@@ -669,8 +669,8 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
|
||||
if (waveformat.uiFormatTag != WAVE_FORMAT_PCM)
|
||||
return false;
|
||||
|
||||
if (waveformat.ulSamplesPerSec !=
|
||||
waveformat.ulAvgBytesPerSec / waveformat.uiBlockAlign)
|
||||
if (waveformat.ulAvgBytesPerSec !=
|
||||
waveformat.ulSamplesPerSec * waveformat.uiBlockAlign)
|
||||
return false;
|
||||
|
||||
// get file size from header
|
||||
|
Reference in New Issue
Block a user