Bug 1439046 - Guard against division by zero in DynamicsCompressorKernel.cpp. r?pehrsons draft
authorPaul Adenot <paul@paul.cx>
Fri, 23 Feb 2018 14:06:51 +0100
changeset 759640 ef5fac1194fc1f722656a6326aa47722ecc27756
parent 759639 ee3fdd1fb7beb534833a6677733a8fec44e05ec9
push id100417
push userpaul@paul.cx
push dateMon, 26 Feb 2018 09:53:47 +0000
reviewerspehrsons
bugs1439046
milestone60.0a1
Bug 1439046 - Guard against division by zero in DynamicsCompressorKernel.cpp. r?pehrsons MozReview-Commit-ID: 2DlebpogUHm
dom/media/webaudio/blink/DynamicsCompressorKernel.cpp
--- 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;