Bug 1390352 - Add check the return value of Servo_AnimationValues_ComputeDistance. r?hiro draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Mon, 21 Aug 2017 16:22:00 +0900
changeset 649731 7b6077825bb8b3f14783471b28ad2693d3d3208a
parent 649730 edd09250b55736bf227dced8ca012241f52ddeba
child 727164 b3197e2c952eecb3d3b5a95a62e8d6a29536755f
push id75124
push userbmo:mantaroh@gmail.com
push dateMon, 21 Aug 2017 07:22:26 +0000
reviewershiro
bugs1390352
milestone57.0a1
Bug 1390352 - Add check the return value of Servo_AnimationValues_ComputeDistance. r?hiro We need to check the return value of Servo_AnimationValues_ComputeDistance in order to check whether we support the specified paced animation value. Servo_AnimationValues_ComputeDistance will return a negative value when the function fails, So this patch make handling this failure pattern. MozReview-Commit-ID: 7UB3wJEQxmz
dom/smil/nsSMILCSSValueType.cpp
layout/style/StyleAnimationValue.cpp
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -451,16 +451,20 @@ ComputeDistanceForServo(const ValueWrapp
       aFromWrapper ? &aFromWrapper->mServoValues[0] : nullptr;
     const RefPtr<RawServoAnimationValue>* toValue = &aToWrapper.mServoValues[0];
     RefPtr<RawServoAnimationValue> zeroValueStorage;
     if (!FinalizeServoAnimationValues(fromValue, toValue, zeroValueStorage)) {
       return NS_ERROR_FAILURE;
     }
 
     double distance = Servo_AnimationValues_ComputeDistance(*fromValue, *toValue);
+    if (distance < 0.0) {
+      return NS_ERROR_FAILURE;
+    }
+
     if (len == 1) {
       aDistance = distance;
       return NS_OK;
     }
     squareDistance += distance * distance;
   }
 
   aDistance = sqrt(squareDistance);
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -5395,21 +5395,24 @@ AnimationValue::ComputeDistance(nsCSSPro
     return 0.0;
   }
 
   MOZ_ASSERT(!mServo != mGecko.IsNull());
   MOZ_ASSERT(mGecko.IsNull() == aOther.mGecko.IsNull() &&
              !mServo == !aOther.mServo,
              "Animation values should have the same style engine");
 
+  double distance= 0.0;
   if (mServo) {
-    return Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo);
+    distance = Servo_AnimationValues_ComputeDistance(mServo, aOther.mServo);
+    return distance < 0.0
+           ? 0.0
+           : distance;
   }
 
-  double distance = 0.0;
   return StyleAnimationValue::ComputeDistance(aProperty,
                                               mGecko,
                                               aOther.mGecko,
                                               aStyleContext->AsGecko(),
                                               distance)
          ? distance
          : 0.0;
 }