diff --git a/taglib/mpc/mpcproperties.cpp b/taglib/mpc/mpcproperties.cpp index 144473ed..5f013760 100644 --- a/taglib/mpc/mpcproperties.cpp +++ b/taglib/mpc/mpcproperties.cpp @@ -245,11 +245,13 @@ void MPC::Properties::readSV8(File *file, offset_t streamLength) // undefined. Leave the fields at their defaults rather than converting. const auto length = static_cast(frameCount) * 1000.0 / d->sampleRate; - if(length > 0.0 && length < static_cast(std::numeric_limits::max())) { + if(length > 0.0 && + length + 0.5 <= 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())) + if(bitrate >= 0.0 && + bitrate + 0.5 <= static_cast(std::numeric_limits::max())) d->bitrate = static_cast(bitrate + 0.5); } } @@ -350,9 +352,14 @@ void MPC::Properties::readSV7(const ByteVector &data, offset_t streamLength) 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); + if(length + 0.5 <= static_cast(std::numeric_limits::max())) { + d->length = static_cast(length + 0.5); - if(d->bitrate == 0) - d->bitrate = static_cast(static_cast(streamLength) * 8.0 / length + 0.5); + if(d->bitrate == 0) { + const double bitrate = static_cast(streamLength) * 8.0 / length; + if(bitrate + 0.5 <= static_cast(std::numeric_limits::max())) + d->bitrate = static_cast(bitrate + 0.5); + } + } } }