Merge pull request #476 from TsudaKageyu/fuzzed-ape

Some fixes for fuzzed APE files.
This commit is contained in:
Lukáš Lalinský
2014-12-29 09:47:10 +01:00
5 changed files with 27 additions and 6 deletions

View File

@ -221,12 +221,20 @@ void APE::Properties::analyzeOld()
blocksPerFrame = 73728;
else
blocksPerFrame = 9216;
d->channels = header.toShort(4, false);
d->sampleRate = header.toUInt(6, false);
const uint finalFrameBlocks = header.toUInt(22, false);
const uint totalBlocks
= totalFrames > 0 ? (totalFrames - 1) * blocksPerFrame + finalFrameBlocks : 0;
d->length = totalBlocks / d->sampleRate;
d->bitrate = d->length > 0 ? ((d->streamLength * 8L) / d->length) / 1000 : 0;
uint totalBlocks = 0;
if(totalFrames > 0)
totalBlocks = (totalFrames - 1) * blocksPerFrame + finalFrameBlocks;
if(d->sampleRate > 0)
d->length = totalBlocks / d->sampleRate;
if(d->length > 0)
d->bitrate = ((d->streamLength * 8L) / d->length) / 1000;
}

View File

@ -368,10 +368,13 @@ ByteVector APE::Tag::render() const
void APE::Tag::parse(const ByteVector &data)
{
uint pos = 0;
// 11 bytes is the minimum size for an APE item
if(data.size() < 11)
return;
uint pos = 0;
for(uint i = 0; i < d->footer.itemCount() && pos <= data.size() - 11; i++) {
APE::Item item;
item.parse(data.mid(pos));