From c9ebb00ed086c63928befecf5ff24c1424d5793a Mon Sep 17 00:00:00 2001 From: Adam Stark Date: Sun, 17 Jan 2021 22:51:09 +0000 Subject: [PATCH] Catch issue where the number of samples in the metadata is larger than the actual file data --- AudioFile.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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];