Bug 1439046 - Guard against division by zero in DynamicsCompressorKernel.cpp. r?pehrsons
MozReview-Commit-ID: 2DlebpogUHm
--- a/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp
+++ b/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp
@@ -34,16 +34,17 @@
#include "mozilla/FloatingPoint.h"
#include "WebAudioUtils.h"
using namespace std;
using namespace mozilla::dom; // for WebAudioUtils
using mozilla::IsInfinite;
+using mozilla::PositiveInfinity;
using mozilla::IsNaN;
using mozilla::MakeUnique;
namespace WebCore {
// Metering hits peaks instantly, but releases this fast (in seconds).
const float meteringReleaseTimeConstant = 0.325f;
@@ -316,17 +317,23 @@ void DynamicsCompressorKernel::process(f
// envelopeRate is the rate we slew from current compressor level to the desired level.
// The exact rate depends on if we're attacking or releasing and by how much.
float envelopeRate;
bool isReleasing = scaledDesiredGain > m_compressorGain;
// compressionDiffDb is the difference between current compression level and the desired level.
- float compressionDiffDb = WebAudioUtils::ConvertLinearToDecibels(m_compressorGain / scaledDesiredGain, -1000.0f);
+ float compressionDiffDb;
+ if (scaledDesiredGain == 0.0) {
+ compressionDiffDb = PositiveInfinity<float>();
+ } else {
+ compressionDiffDb = WebAudioUtils::ConvertLinearToDecibels(m_compressorGain / scaledDesiredGain, -1000.0f);
+ }
+
if (isReleasing) {
// Release mode - compressionDiffDb should be negative dB
m_maxAttackCompressionDiffDb = -1;
// Fix gremlins.
if (IsNaN(compressionDiffDb))
compressionDiffDb = -1;