From 932f384c87959790fc47fe1099c8ac54530c1b3d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Dec 2017 17:37:21 +0100 Subject: [PATCH] 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. --- src/unix/sound.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index 53e3f31240..e0913ee65d 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -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