Skip to content

Commit

Permalink
Catch issue where the number of samples in the metadata is larger tha…
Browse files Browse the repository at this point in the history
…n the actual file data
  • Loading branch information
adamstark committed Jan 17, 2021
1 parent 829508c commit c9ebb00
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ bool AudioFile<T>::decodeWaveFile (std::vector<uint8_t>& 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]);
Expand Down Expand Up @@ -702,6 +708,12 @@ bool AudioFile<T>::decodeAiffFile (std::vector<uint8_t>& 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];
Expand Down

0 comments on commit c9ebb00

Please sign in to comment.