[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>
This commit is contained in:
parent
fe82b5ed65
commit
ffdb6262c2
1 changed files with 5 additions and 1 deletions
|
@ -436,8 +436,12 @@
|
||||||
return;
|
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
|
// 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);
|
// DLog(@"End of file. %li", totalFrames - _endPadding - _framesDecoded);
|
||||||
sampleCount = totalFrames - _endPadding - _framesDecoded + startingSample;
|
sampleCount = totalFrames - _endPadding - _framesDecoded + startingSample;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue