Skip to content

Commit

Permalink
[Bugfix] Add missing early return in AudioSubsectionReader::readSampl…
Browse files Browse the repository at this point in the history
…es()

Looks like a very old regression since 27895cb

In case clearSamplesBeyondAvailableLength() returns a negative number of samples, we need to avoid calling readSamples() on the source reader. One reason is that it's possible the source reader readSamples() will also call clearSamplesBeyondAvailableLength(), which can end up calling zeromem() with that negative number of samples, causing a crash. (that would happen in case samplesAvailable's value would be an even lower negative number, causing the condition `(samplesAvailable < numSamples)` to evaluate to true).
  • Loading branch information
danra committed Jul 28, 2023
1 parent 0f80e1b commit 6e618fa
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ bool AudioSubsectionReader::readSamples (int* const* destSamples, int numDestCha
clearSamplesBeyondAvailableLength (destSamples, numDestChannels, startOffsetInDestBuffer,
startSampleInFile, numSamples, length);

if (numSamples <= 0)
return true;

return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
startSampleInFile + startSample, numSamples);
}
Expand Down

0 comments on commit 6e618fa

Please sign in to comment.