From 61c7cf9a9c5d743fee16094f491fa83c03391eb8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 30 Dec 2017 17:45:01 +0100 Subject: [PATCH] Fix yet another division by 0 when parsing WAV data Ensure that the size of one sample (including all the channels) is non zero before dividing by it. --- src/unix/sound.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/unix/sound.cpp b/src/unix/sound.cpp index e0913ee65d..9697c36af4 100644 --- a/src/unix/sound.cpp +++ b/src/unix/sound.cpp @@ -673,6 +673,13 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData) waveformat.ulSamplesPerSec * waveformat.uiBlockAlign) return false; + // We divide by this number below to obtain the number of samples, so it + // definitely can't be 0. + wxUint32 const sampleSize = + waveformat.uiChannels * waveformat.uiBitsPerSample / 8; + if (!sampleSize) + return false; + // get file size from header wxUint32 chunkSize; memcpy(&chunkSize, &data[4], 4); @@ -695,7 +702,7 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData) m_data->m_channels = waveformat.uiChannels; m_data->m_samplingRate = waveformat.ulSamplesPerSec; m_data->m_bitsPerSample = waveformat.uiBitsPerSample; - m_data->m_samples = ul / (m_data->m_channels * m_data->m_bitsPerSample / 8); + m_data->m_samples = ul / sampleSize; m_data->m_dataBytes = ul; if (copyData)