From: Tsuda Kageyu Date: Tue, 23 Dec 2014 11:54:20 +0000 (+0900) Subject: Fix a division by zero error when parsing an APE file. X-Git-Tag: v1.10beta~133^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4a9614bfc376a31f4995db9c294df8466f843eb6;p=taglib Fix a division by zero error when parsing an APE file. --- diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index 4940edea..cf829fe5 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -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; }