diff --git a/taglib/ape/apeproperties.cpp b/taglib/ape/apeproperties.cpp index 84d07628..f9f3d8bd 100644 --- a/taglib/ape/apeproperties.cpp +++ b/taglib/ape/apeproperties.cpp @@ -29,6 +29,8 @@ #include "apeproperties.h" +#include + #include "tdebug.h" #include "apefile.h" #include "apefooter.h" @@ -136,10 +138,19 @@ void APE::Properties::read(File *file, offset_t streamLength) else analyzeOld(file); + // Both the frame count and the sample rate are read from the file, so the + // millisecond length can land outside int, and a short stream at a high rate + // does the same to the bitrate. Converting a double the destination type + // cannot represent is undefined, so leave the field at its default instead. if(d->sampleFrames > 0 && d->sampleRate > 0) { const auto length = static_cast(d->sampleFrames) * 1000.0 / d->sampleRate; - d->length = static_cast(length + 0.5); - d->bitrate = static_cast(static_cast(streamLength) * 8.0 / length + 0.5); + if(length > 0.0 && length < static_cast(std::numeric_limits::max())) { + d->length = static_cast(length + 0.5); + + const double bitrate = static_cast(streamLength) * 8.0 / length; + if(bitrate >= 0.0 && bitrate < static_cast(std::numeric_limits::max())) + d->bitrate = static_cast(bitrate + 0.5); + } } }