[MAD Decoder] Fix sample count calculation crash
This condition would underflow when skipping a bunch of samples on the start of playback, or otherwise seeking, and could cause an unsigned underflow, which would cause the subsequent vDSP_vflt32 to overread into the MAD sample buffer and crash. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
fe82b5ed65
commit
ffdb6262c2
|
@ -436,8 +436,12 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// Clip this for the following calculation, so this doesn't underflow
|
||||
// when seeking and skipping a lot of samples
|
||||
unsigned long startingSampleClipped = MIN(startingSample, sampleCount);
|
||||
|
||||
// We are at the end of the file and need to read the last few frames
|
||||
if(_framesDecoded + (sampleCount - startingSample) > totalFrames - _endPadding) {
|
||||
if(_framesDecoded + (sampleCount - startingSampleClipped) > totalFrames - _endPadding) {
|
||||
// DLog(@"End of file. %li", totalFrames - _endPadding - _framesDecoded);
|
||||
sampleCount = totalFrames - _endPadding - _framesDecoded + startingSample;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue