Avoid integer overflow when computing the sample size
While it seems to be harmless in this particular case, it still prevents testing this code with UBSAN by triggering it here, so check that multiplication doesn't overflow.
This commit is contained in:
@@ -673,10 +673,16 @@ bool wxSound::LoadWAV(const void* data_, size_t length, bool copyData)
|
|||||||
waveformat.ulSamplesPerSec * waveformat.uiBlockAlign)
|
waveformat.ulSamplesPerSec * waveformat.uiBlockAlign)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// We divide by this number below to obtain the number of samples, so it
|
// We divide by the sample size below to obtain the number of samples, so
|
||||||
// definitely can't be 0.
|
// it definitely can't be 0. Also take care to avoid integer overflow when
|
||||||
wxUint32 const sampleSize =
|
// computing it.
|
||||||
waveformat.uiChannels * waveformat.uiBitsPerSample / 8;
|
unsigned tmp = waveformat.uiChannels;
|
||||||
|
if (tmp >= 0x10000)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tmp *= waveformat.uiBitsPerSample;
|
||||||
|
|
||||||
|
wxUint32 const sampleSize = tmp / 8;
|
||||||
if (!sampleSize)
|
if (!sampleSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user