diff --git a/AudioFile.h b/AudioFile.h index a9f26c6..badd70f 100644 --- a/AudioFile.h +++ b/AudioFile.h @@ -564,6 +564,12 @@ bool AudioFile::decodeWaveFile (std::vector& fileData) { int sampleIndex = samplesStartIndex + (numBytesPerBlock * i) + channel * numBytesPerSample; + if ((sampleIndex + (bitDepth / 8)) >= fileData.size()) + { + reportError ("ERROR: read file error as the metadata indicates more samples than there are in the file data"); + return false; + } + if (bitDepth == 8) { T sample = singleByteToSample (fileData[sampleIndex]); @@ -702,6 +708,12 @@ bool AudioFile::decodeAiffFile (std::vector& fileData) { int sampleIndex = samplesStartIndex + (numBytesPerFrame * i) + channel * numBytesPerSample; + if ((sampleIndex + (bitDepth / 8)) >= fileData.size()) + { + reportError ("ERROR: read file error as the metadata indicates more samples than there are in the file data"); + return false; + } + if (bitDepth == 8) { int8_t sampleAsSigned8Bit = (int8_t)fileData[sampleIndex];