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:
Vadim Zeitlin
2017-12-30 17:37:21 +01:00
parent 45e8d13e13
commit 932f384c87

View File

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